source: uKadecot/trunk/tools/EcnlControllerUI/EcnlCtrlUI/js/linq.min.js@ 101

Last change on this file since 101 was 101, checked in by coas-nagasima, 9 years ago

TOPPERS/uKadecotのソースコードを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/plain
File size: 33.0 KB
Line 
1(function(q,g){var d={Identity:function(a){return a},True:function(){return true},Blank:function(){}},f={Boolean:typeof true,Number:typeof 0,String:typeof"",Object:typeof{},Undefined:typeof g,Function:typeof function(){}},b={createLambda:function(a){if(a==null)return d.Identity;if(typeof a==f.String)if(a=="")return d.Identity;else if(a.indexOf("=>")==-1){var l=new RegExp("[$]+","g"),b=0,i;while(i=l.exec(a)){var e=i[0].length;if(e>b)b=e}for(var g=[],c=1;c<=b;c++){for(var h="",k=0;k<c;k++)h+="$";g.push(h)}var m=Array.prototype.join.call(g,",");return new Function(m,"return "+a)}else{var j=a.match(/^[(\s]*([^()]*?)[)\s]*=>(.*)/);return new Function(j[1],"return "+j[2])}return a},isIEnumerable:function(a){if(typeof Enumerator!==f.Undefined)try{new Enumerator(a);return true}catch(b){}return false},defineProperty:Object.defineProperties!=null?function(b,a,c){Object.defineProperty(b,a,{enumerable:false,configurable:true,writable:true,value:c})}:function(b,a,c){b[a]=c},compare:function(a,b){return a===b?0:a>b?1:-1},dispose:function(a){a!=null&&a.dispose()}},k={Before:0,Running:1,After:2},c=function(c,d,e){var b=new r,a=k.Before;this.current=b.current;this.reset=function(){throw new Error("Reset is not supported");};this.moveNext=function(){try{switch(a){case k.Before:a=k.Running;c();case k.Running:if(d.apply(b))return true;else{this.dispose();return false}case k.After:return false}}catch(e){this.dispose();throw e;}};this.dispose=function(){if(a!=k.Running)return;try{e()}finally{a=k.After}}},m={};ss.initAssembly(m,"linq");ss.initClass(c,m,{},null,[ss.IDisposable]);var r=function(){var a=null;this.current=function(){return a};this.yieldReturn=function(b){a=b;return true};this.yieldBreak=function(){return false}},a=function(a){this.getEnumerator=a};ss.initClass(a,m,{},null,[ss.IEnumerable]);a.Utils={};a.Utils.createLambda=function(a){return b.createLambda(a)};a.Utils.createEnumerable=function(b){return new a(b)};a.Utils.createEnumerator=function(a,b,d){return new c(a,b,d)};a.Utils.extendTo=function(h){var d=h.prototype,f;if(h===Array){f=e.prototype;b.defineProperty(d,"getSource",function(){return this})}else{f=a.prototype;b.defineProperty(d,"getEnumerator",function(){return a.from(this).getEnumerator()})}for(var c in f){var g=f[c];if(d[c]==g)continue;if(d[c]!=null){c=c+"ByLinq";if(d[c]==g)continue}g instanceof Function&&b.defineProperty(d,c,g)}};a.choice=function(){var b=arguments;return new a(function(){return new c(function(){b=b[0]instanceof Array?b[0]:b[0].getEnumerator!=null?b[0].toArray():b},function(){return this.yieldReturn(b[Math.floor(Math.random()*b.length)])},d.Blank)})};a.cycle=function(){var b=arguments;return new a(function(){var a=0;return new c(function(){b=b[0]instanceof Array?b[0]:b[0].getEnumerator!=null?b[0].toArray():b},function(){if(a>=b.length)a=0;return this.yieldReturn(b[a++])},d.Blank)})};a.empty=function(){return new a(function(){return new c(d.Blank,function(){return false},d.Blank)})};a.from=function(g){if(g==null)return a.empty();if(g instanceof a)return g;if(typeof g==f.Number||typeof g==f.Boolean)return a.repeat(g,1);if(typeof g==f.String)return new a(function(){var a=0;return new c(d.Blank,function(){return a<g.length?this.yieldReturn(g.charAt(a++)):false},d.Blank)});var i=ss.safeCast(g,ss.IEnumerable);if(i){var h;return new a(function(){return new c(function(){h=ss.getEnumerator(i)},function(){var a=h.moveNext();return a?this.yieldReturn(h.current()):false},function(){var a=ss.safeCast(h,ss.IDisposable);a&&a.dispose()})})}if(typeof g!=f.Function){if(typeof g.length==f.Number)return new e(g);if(!(g instanceof Object)&&b.isIEnumerable(g))return new a(function(){var b=true,a;return new c(function(){a=new Enumerator(g)},function(){if(b)b=false;else a.moveNext();return a.atEnd()?false:this.yieldReturn(a.item())},d.Blank)});if(typeof Windows===f.Object&&typeof g.first===f.Function)return new a(function(){var b=true,a;return new c(function(){a=g.first()},function(){if(b)b=false;else a.moveNext();return a.hasCurrent?this.yieldReturn(a.current):this.yieldBreak()},d.Blank)})}return new a(function(){var a=[],b=0;return new c(function(){for(var b in g){var c=g[b];!(c instanceof Function)&&Object.prototype.hasOwnProperty.call(g,b)&&a.push({key:b,value:c})}},function(){return b<a.length?this.yieldReturn(a[b++]):false},d.Blank)})},a.make=function(b){return a.repeat(b,1)};a.matches=function(f,e,b){if(b==null)b="";if(e instanceof RegExp){b+=e.ignoreCase?"i":"";b+=e.multiline?"m":"";e=e.source}if(b.indexOf("g")===-1)b+="g";return new a(function(){var a;return new c(function(){a=new RegExp(e,b)},function(){var b=a.exec(f);return b?this.yieldReturn(b):false},d.Blank)})};a.range=function(f,e,b){if(b==null)b=1;return new a(function(){var a,g=0;return new c(function(){a=f-b},function(){return g++<e?this.yieldReturn(a+=b):this.yieldBreak()},d.Blank)})};a.rangeDown=function(f,e,b){if(b==null)b=1;return new a(function(){var a,g=0;return new c(function(){a=f+b},function(){return g++<e?this.yieldReturn(a-=b):this.yieldBreak()},d.Blank)})};a.rangeTo=function(e,f,b){if(b==null)b=1;return e<f?new a(function(){var a;return new c(function(){a=e-b},function(){var c=a+=b;return c<=f?this.yieldReturn(c):this.yieldBreak()},d.Blank)}):new a(function(){var a;return new c(function(){a=e+b},function(){var c=a-=b;return c>=f?this.yieldReturn(c):this.yieldBreak()},d.Blank)})};a.repeat=function(b,e){return e!=null?a.repeat(b).take(e):new a(function(){return new c(d.Blank,function(){return this.yieldReturn(b)},d.Blank)})};a.repeatWithFinalize=function(d,e){d=b.createLambda(d);e=b.createLambda(e);return new a(function(){var a;return new c(function(){a=d()},function(){return this.yieldReturn(a)},function(){if(a!=null){e(a);a=null}})})};a.generate=function(e,f){if(f!=null)return a.generate(e).take(f);e=b.createLambda(e);return new a(function(){return new c(d.Blank,function(){return this.yieldReturn(e())},d.Blank)})};a.toInfinity=function(e,b){if(e==null)e=0;if(b==null)b=1;return new a(function(){var a;return new c(function(){a=e-b},function(){return this.yieldReturn(a+=b)},d.Blank)})};a.toNegativeInfinity=function(e,b){if(e==null)e=0;if(b==null)b=1;return new a(function(){var a;return new c(function(){a=e+b},function(){return this.yieldReturn(a-=b)},d.Blank)})};a.unfold=function(f,e){e=b.createLambda(e);return new a(function(){var b=true,a;return new c(d.Blank,function(){if(b){b=false;a=f;return this.yieldReturn(a)}a=e(a);return this.yieldReturn(a)},d.Blank)})};a.defer=function(d){return new a(function(){var e;return new c(function(){e=a.from(d()).getEnumerator()},function(){return e.moveNext()?this.yieldReturn(e.current()):this.yieldBreak()},function(){b.dispose(e)})})};a.prototype.traverseBreadthFirst=function(e,d){var f=this;e=b.createLambda(e);d=b.createLambda(d);return new a(function(){var g,i=0,h=[];return new c(function(){g=f.getEnumerator()},function(){while(true){if(g.moveNext()){h.push(g.current());return this.yieldReturn(d(g.current(),i))}var c=a.from(h).selectMany(function(a){return e(a)});if(!c.any())return false;else{i++;h=[];b.dispose(g);g=c.getEnumerator()}}},function(){b.dispose(g)})})};a.prototype.traverseDepthFirst=function(e,d){var f=this;e=b.createLambda(e);d=b.createLambda(d);return new a(function(){var h=[],g;return new c(function(){g=f.getEnumerator()},function(){while(true){if(g.moveNext()){var c=d(g.current(),h.length);h.push(g);g=a.from(e(g.current())).getEnumerator();return this.yieldReturn(c)}if(h.length<=0)return false;b.dispose(g);g=h.pop()}},function(){try{b.dispose(g)}finally{a.from(h).forEach(function(a){a.dispose()})}})})};a.prototype.flatten=function(){var e=this;return new a(function(){var g,f=null;return new c(function(){g=e.getEnumerator()},function(){while(true){if(f!=null)if(f.moveNext())return this.yieldReturn(f.current());else f=null;if(g.moveNext())if(g.current()instanceof Array){b.dispose(f);f=a.from(g.current()).selectMany(d.Identity).flatten().getEnumerator();continue}else return this.yieldReturn(g.current());return false}},function(){try{b.dispose(g)}finally{b.dispose(f)}})})};a.prototype.pairwise=function(d){var e=this;d=b.createLambda(d);return new a(function(){var a;return new c(function(){a=e.getEnumerator();a.moveNext()},function(){var b=a.current();return a.moveNext()?this.yieldReturn(d(b,a.current())):false},function(){b.dispose(a)})})};a.prototype.scan=function(f,d){var e;if(d==null){d=b.createLambda(f);e=false}else{d=b.createLambda(d);e=true}var g=this;return new a(function(){var a,h,i=true;return new c(function(){a=g.getEnumerator()},function(){if(i){i=false;if(!e){if(a.moveNext())return this.yieldReturn(h=a.current())}else return this.yieldReturn(h=f)}return a.moveNext()?this.yieldReturn(h=d(h,a.current())):false},function(){b.dispose(a)})})};a.prototype.select=function(d){d=b.createLambda(d);if(d.length<=1)return new i(this,null,d);else{var e=this;return new a(function(){var a,f=0;return new c(function(){a=e.getEnumerator()},function(){return a.moveNext()?this.yieldReturn(d(a.current(),f++)):false},function(){b.dispose(a)})})}};a.prototype.selectMany=function(e,d){var f=this;e=b.createLambda(e);if(d==null)d=function(b,a){return a};d=b.createLambda(d);return new a(function(){var i,h=g,j=0;return new c(function(){i=f.getEnumerator()},function(){if(h===g)if(!i.moveNext())return false;do{if(h==null){var c=e(i.current(),j++);h=a.from(c).getEnumerator()}if(h.moveNext())return this.yieldReturn(d(i.current(),h.current()));b.dispose(h);h=null}while(i.moveNext());return false},function(){try{b.dispose(i)}finally{b.dispose(h)}})})};a.prototype.where=function(d){d=b.createLambda(d);if(d.length<=1)return new j(this,d);else{var e=this;return new a(function(){var a,f=0;return new c(function(){a=e.getEnumerator()},function(){while(a.moveNext())if(d(a.current(),f++))return this.yieldReturn(a.current());return false},function(){b.dispose(a)})})}};a.prototype.choose=function(d){d=b.createLambda(d);var e=this;return new a(function(){var a,f=0;return new c(function(){a=e.getEnumerator()},function(){while(a.moveNext()){var b=d(a.current(),f++);if(b!=null)return this.yieldReturn(b)}return this.yieldBreak()},function(){b.dispose(a)})})};a.prototype.ofType=function(e){var d=this;return new a(function(){var a;return new c(function(){a=ss.getEnumerator(d)},function(){while(a.moveNext()){var b=ss.safeCast(a.current(),e);if(ss.isValue(b))return this.yieldReturn(b)}return false},function(){b.dispose(a)})})};a.prototype.zip=function(){var g=arguments,d=b.createLambda(arguments[arguments.length-1]),e=this;if(arguments.length==2){var f=arguments[0];return new a(function(){var h,g,i=0;return new c(function(){h=e.getEnumerator();g=a.from(f).getEnumerator()},function(){return h.moveNext()&&g.moveNext()?this.yieldReturn(d(h.current(),g.current(),i++)):false},function(){try{b.dispose(h)}finally{b.dispose(g)}})})}else return new a(function(){var f,h=0;return new c(function(){var b=a.make(e).concat(a.from(g).takeExceptLast().select(a.from)).select(function(a){return a.getEnumerator()}).toArray();f=a.from(b)},function(){if(f.all(function(a){return a.moveNext()})){var a=f.select(function(a){return a.current()}).toArray();a.push(h++);return this.yieldReturn(d.apply(null,a))}else return this.yieldBreak()},function(){a.from(f).forEach(b.dispose)})})};a.prototype.merge=function(){var e=arguments,d=this;return new a(function(){var f,g=-1;return new c(function(){f=a.make(d).concat(a.from(e).select(a.from)).select(function(a){return a.getEnumerator()}).toArray()},function(){while(f.length>0){g=g>=f.length-1?0:g+1;var a=f[g];if(a.moveNext())return this.yieldReturn(a.current());else{a.dispose();f.splice(g--,1)}}return this.yieldBreak()},function(){a.from(f).forEach(b.dispose)})})};a.prototype.join=function(k,f,e,h,i){f=b.createLambda(f);e=b.createLambda(e);h=b.createLambda(h);var j=this;return new a(function(){var l,o,m=null,n=0;return new c(function(){l=j.getEnumerator();o=a.from(k).toLookup(e,d.Identity,i)},function(){while(true){if(m!=null){var a=m[n++];if(a!==g)return this.yieldReturn(h(l.current(),a));a=null;n=0}if(l.moveNext()){var b=f(l.current());m=o.get(b).toArray()}else return false}},function(){b.dispose(l)})})};a.prototype.groupJoin=function(j,f,e,g,i){f=b.createLambda(f);e=b.createLambda(e);g=b.createLambda(g);var h=this;return new a(function(){var k=h.getEnumerator(),l=null;return new c(function(){k=h.getEnumerator();l=a.from(j).toLookup(e,d.Identity,i)},function(){if(k.moveNext()){var a=l.get(f(k.current()));return this.yieldReturn(g(k.current(),a))}return false},function(){b.dispose(k)})})};a.prototype.all=function(a){a=b.createLambda(a);var c=true;this.forEach(function(b){if(!a(b)){c=false;return false}});return c};a.prototype.any=function(c){c=b.createLambda(c);var a=this.getEnumerator();try{if(arguments.length==0)return a.moveNext();while(a.moveNext())if(c(a.current()))return true;return false}finally{b.dispose(a)}};a.prototype.isEmpty=function(){return!this.any()};a.prototype.concat=function(){var d=this;if(arguments.length==1){var e=arguments[0];return new a(function(){var g,f;return new c(function(){g=d.getEnumerator()},function(){if(f==null){if(g.moveNext())return this.yieldReturn(g.current());f=a.from(e).getEnumerator()}return f.moveNext()?this.yieldReturn(f.current()):false},function(){try{b.dispose(g)}finally{b.dispose(f)}})})}else{var f=arguments;return new a(function(){var e;return new c(function(){e=a.make(d).concat(a.from(f).select(a.from)).select(function(a){return a.getEnumerator()}).toArray()},function(){while(e.length>0){var a=e[0];if(a.moveNext())return this.yieldReturn(a.current());else{a.dispose();e.splice(0,1)}}return this.yieldBreak()},function(){a.from(e).forEach(b.dispose)})})}};a.prototype.insert=function(f,d){var e=this;return new a(function(){var h,g,j=0,i=false;return new c(function(){h=e.getEnumerator();g=a.from(d).getEnumerator()},function(){if(j==f&&g.moveNext()){i=true;return this.yieldReturn(g.current())}if(h.moveNext()){j++;return this.yieldReturn(h.current())}return!i&&g.moveNext()?this.yieldReturn(g.current()):false},function(){try{b.dispose(h)}finally{b.dispose(g)}})})};a.prototype.alternate=function(d){var e=this;return new a(function(){var h,g,i,f;return new c(function(){if(d instanceof Array||d.getEnumerator!=null)i=a.from(a.from(d).toArray());else i=a.make(d);g=e.getEnumerator();if(g.moveNext())h=g.current()},function(){while(true){if(f!=null)if(f.moveNext())return this.yieldReturn(f.current());else f=null;if(h==null&&g.moveNext()){h=g.current();f=i.getEnumerator();continue}else if(h!=null){var a=h;h=null;return this.yieldReturn(a)}return this.yieldBreak()}},function(){try{b.dispose(g)}finally{b.dispose(f)}})})};a.prototype.contains=function(d,c){c=c||ss.EqualityComparer.def;var a=this.getEnumerator();try{while(a.moveNext())if(c.areEqual(a.current(),d))return true;return false}finally{b.dispose(a)}};a.prototype.defaultIfEmpty=function(d){var e=this;if(d===g)d=null;return new a(function(){var a,f=true;return new c(function(){a=e.getEnumerator()},function(){if(a.moveNext()){f=false;return this.yieldReturn(a.current())}else if(f){f=false;return this.yieldReturn(d)}return false},function(){b.dispose(a)})})};a.prototype.distinct=function(b){return this.except(a.empty(),b)};a.prototype.distinctUntilChanged=function(d){d=b.createLambda(d);var e=this;return new a(function(){var a,f,g;return new c(function(){a=e.getEnumerator()},function(){while(a.moveNext()){var b=d(a.current());if(g){g=false;f=b;return this.yieldReturn(a.current())}if(f===b)continue;f=b;return this.yieldReturn(a.current())}return this.yieldBreak()},function(){b.dispose(a)})})};a.prototype.except=function(e,d){var f=this;return new a(function(){var g,h;return new c(function(){g=f.getEnumerator();h=new(ss.makeGenericType(ss.Dictionary$2,[Object,Object]))(null,d);a.from(e).forEach(function(a){h.add(a)})},function(){while(g.moveNext()){var a=g.current();if(!h.containsKey(a)){h.add(a);return this.yieldReturn(a)}}return false},function(){b.dispose(g)})})};a.prototype.intersect=function(e,d){var f=this;return new a(function(){var g,h,i;return new c(function(){g=f.getEnumerator();h=new(ss.makeGenericType(ss.Dictionary$2,[Object,Object]))(null,d);a.from(e).forEach(function(a){h.add(a)});i=new(ss.makeGenericType(ss.Dictionary$2,[Object,Object]))(null,d)},function(){while(g.moveNext()){var a=g.current();if(!i.containsKey(a)&&h.containsKey(a)){i.add(a);return this.yieldReturn(a)}}return false},function(){b.dispose(g)})})};a.prototype.sequenceEqual=function(f,e){e=e||ss.EqualityComparer.def;var d=this.getEnumerator();try{var c=a.from(f).getEnumerator();try{while(d.moveNext())if(!c.moveNext()||!e.areEqual(d.current(),c.current()))return false;return c.moveNext()?false:true}finally{b.dispose(c)}}finally{b.dispose(d)}};a.prototype.union=function(e,d){var f=this;return new a(function(){var j,h,i;return new c(function(){j=f.getEnumerator();i=new(ss.makeGenericType(ss.Dictionary$2,[Object,Object]))(null,d)},function(){var b;if(h===g){while(j.moveNext()){b=j.current();if(!i.containsKey(b)){i.add(b);return this.yieldReturn(b)}}h=a.from(e).getEnumerator()}while(h.moveNext()){b=h.current();if(!i.containsKey(b)){i.add(b);return this.yieldReturn(b)}}return false},function(){try{b.dispose(j)}finally{b.dispose(h)}})})};a.prototype.orderBy=function(a,b){return new h(this,a,b,false)};a.prototype.orderByDescending=function(a,b){return new h(this,a,b,true)};a.prototype.reverse=function(){var b=this;return new a(function(){var a,e;return new c(function(){a=b.toArray();e=a.length},function(){return e>0?this.yieldReturn(a[--e]):false},d.Blank)})};a.prototype.shuffle=function(){var b=this;return new a(function(){var a;return new c(function(){a=b.toArray()},function(){if(a.length>0){var b=Math.floor(Math.random()*a.length);return this.yieldReturn(a.splice(b,1)[0])}return false},d.Blank)})};a.prototype.weightedSample=function(e){e=b.createLambda(e);var f=this;return new a(function(){var a,b=0;return new c(function(){a=f.choose(function(c){var a=e(c);if(a<=0)return null;b+=a;return{value:c,bound:b}}).toArray()},function(){if(a.length>0){var f=Math.floor(Math.random()*b)+1,e=-1,c=a.length;while(c-e>1){var d=Math.floor((e+c)/2);if(a[d].bound>=f)c=d;else e=d}return this.yieldReturn(a[c].value)}return this.yieldBreak()},d.Blank)})};a.prototype.groupBy=function(f,e,d,g){var h=this;f=b.createLambda(f);e=b.createLambda(e);if(d!=null)d=b.createLambda(d);return new a(function(){var a;return new c(function(){a=h.toLookup(f,e,g).toEnumerable().getEnumerator()},function(){while(a.moveNext())return d==null?this.yieldReturn(a.current()):this.yieldReturn(d(a.current().key(),a.current()));return false},function(){b.dispose(a)})})};a.prototype.partitionBy=function(f,e,d,h){var i=this;f=b.createLambda(f);e=b.createLambda(e);h=h||ss.EqualityComparer.def;var g;if(d==null){g=false;d=function(b,a){return new o(b,a)}}else{g=true;d=b.createLambda(d)}return new a(function(){var j,l,k=[];return new c(function(){j=i.getEnumerator();if(j.moveNext()){l=f(j.current());k.push(e(j.current()))}},function(){var b;while((b=j.moveNext())==true)if(h.areEqual(l,f(j.current())))k.push(e(j.current()));else break;if(k.length>0){var c=g?d(l,a.from(k)):d(l,k);if(b){l=f(j.current());k=[e(j.current())]}else k=[];return this.yieldReturn(c)}return false},function(){b.dispose(j)})})};a.prototype.buffer=function(e){var d=this;return new a(function(){var a;return new c(function(){a=d.getEnumerator()},function(){var b=[],c=0;while(a.moveNext()){b.push(a.current());if(++c>=e)return this.yieldReturn(b)}return b.length>0?this.yieldReturn(b):false},function(){b.dispose(a)})})};a.prototype.aggregate=function(d,c,a){a=b.createLambda(a);return a(this.scan(d,c,a).last())};a.prototype.average=function(a){a=b.createLambda(a);var d=0,c=0;this.forEach(function(b){d+=a(b);++c});return d/c};a.prototype.count=function(a){a=a==null?d.True:b.createLambda(a);var c=0;this.forEach(function(d,b){if(a(d,b))++c});return c};a.prototype.max=function(a){if(a==null)a=d.Identity;return this.select(a).aggregate(function(a,b){return a>b?a:b})};a.prototype.min=function(a){if(a==null)a=d.Identity;return this.select(a).aggregate(function(a,b){return a<b?a:b})};a.prototype.maxBy=function(a){a=b.createLambda(a);return this.aggregate(function(b,c){return a(b)>a(c)?b:c})};a.prototype.minBy=function(a){a=b.createLambda(a);return this.aggregate(function(b,c){return a(b)<a(c)?b:c})};a.prototype.sum=function(a){if(a==null)a=d.Identity;return this.select(a).aggregate(0,function(a,b){return a+b})};a.prototype.elementAt=function(c){var b,a=false;this.forEach(function(e,d){if(d==c){b=e;a=true;return false}});if(!a)throw new Error("index is less than 0 or greater than or equal to the number of elements in source.");return b};a.prototype.elementAtOrDefault=function(d,a){if(a===g)a=null;var c,b=false;this.forEach(function(e,a){if(a==d){c=e;b=true;return false}});return!b?a:c};a.prototype.first=function(a){if(a!=null)return this.where(a).first();var c,b=false;this.forEach(function(a){c=a;b=true;return false});if(!b)throw new Error("first:No element satisfies the condition.");return c};a.prototype.firstOrDefault=function(b,a){if(a===g)a=null;if(b!=null)return this.where(b).firstOrDefault(null,a);var d,c=false;this.forEach(function(a){d=a;c=true;return false});return!c?a:d};a.prototype.last=function(a){if(a!=null)return this.where(a).last();var c,b=false;this.forEach(function(a){b=true;c=a});if(!b)throw new Error("last:No element satisfies the condition.");return c};a.prototype.lastOrDefault=function(b,a){if(a===g)a=null;if(b!=null)return this.where(b).lastOrDefault(null,a);var d,c=false;this.forEach(function(a){c=true;d=a});return!c?a:d};a.prototype.single=function(b){if(b!=null)return this.where(b).single();var c,a=false;this.forEach(function(b){if(!a){a=true;c=b}else throw new Error("single:sequence contains more than one element.");});if(!a)throw new Error("single:No element satisfies the condition.");return c};a.prototype.singleOrDefault=function(c,a){if(a===g)a=null;if(c!=null)return this.where(c).singleOrDefault(null,a);var d,b=false;this.forEach(function(a){if(!b){b=true;d=a}else throw new Error("single:sequence contains more than one element.");});return!b?a:d};a.prototype.skip=function(e){var d=this;return new a(function(){var a,f=0;return new c(function(){a=d.getEnumerator();while(f++<e&&a.moveNext());},function(){return a.moveNext()?this.yieldReturn(a.current()):false},function(){b.dispose(a)})})};a.prototype.skipWhile=function(d){d=b.createLambda(d);var e=this;return new a(function(){var a,g=0,f=false;return new c(function(){a=e.getEnumerator()},function(){while(!f)if(a.moveNext()){if(!d(a.current(),g++)){f=true;return this.yieldReturn(a.current())}continue}else return false;return a.moveNext()?this.yieldReturn(a.current()):false},function(){b.dispose(a)})})};a.prototype.take=function(e){var d=this;return new a(function(){var a,f=0;return new c(function(){a=d.getEnumerator()},function(){return f++<e&&a.moveNext()?this.yieldReturn(a.current()):false},function(){b.dispose(a)})})};a.prototype.takeWhile=function(d){d=b.createLambda(d);var e=this;return new a(function(){var a,f=0;return new c(function(){a=e.getEnumerator()},function(){return a.moveNext()&&d(a.current(),f++)?this.yieldReturn(a.current()):false},function(){b.dispose(a)})})};a.prototype.takeExceptLast=function(d){if(d==null)d=1;var e=this;return new a(function(){if(d<=0)return e.getEnumerator();var a,f=[];return new c(function(){a=e.getEnumerator()},function(){while(a.moveNext()){if(f.length==d){f.push(a.current());return this.yieldReturn(f.shift())}f.push(a.current())}return false},function(){b.dispose(a)})})};a.prototype.takeFromLast=function(d){if(d<=0||d==null)return a.empty();var e=this;return new a(function(){var h,f,g=[];return new c(function(){h=e.getEnumerator()},function(){while(h.moveNext()){g.length==d&&g.shift();g.push(h.current())}if(f==null)f=a.from(g).getEnumerator();return f.moveNext()?this.yieldReturn(f.current()):false},function(){b.dispose(f)})})};a.prototype.indexOf=function(c,b){var a=null;if(typeof c===f.Function)this.forEach(function(d,b){if(c(d,b)){a=b;return false}});else{b=b||ss.EqualityComparer.def;this.forEach(function(e,d){if(b.areEqual(e,c)){a=d;return false}})}return a!==null?a:-1};a.prototype.lastIndexOf=function(c,a){var b=-1;if(typeof c===f.Function)this.forEach(function(d,a){if(c(d,a))b=a});else{a=a||ss.EqualityComparer.def;this.forEach(function(e,d){if(a.areEqual(e,c))b=d})}return b};a.prototype.asEnumerable=function(){return a.from(this)};a.prototype.toArray=function(){var a=[];this.forEach(function(b){a.push(b)});return a};a.prototype.toLookup=function(c,a,f){c=b.createLambda(c);a=b.createLambda(a);var d=new(ss.makeGenericType(ss.Dictionary$2,[Object,Object]))(null,f),e=[];this.forEach(function(h){var b=c(h),f=a(h),g={$:null};if(d.tryGetValue(b,g))g.$.push(f);else{e.push(b);d.add(b,[f])}});return new p(d,e)};a.prototype.toObject=function(c,a){c=b.createLambda(c);a=b.createLambda(a);var d={};this.forEach(function(b){d[c(b)]=a(b)});return d};a.prototype.toDictionary=function(c,a,g,e,f){c=b.createLambda(c);a=b.createLambda(a);var d=new(ss.makeGenericType(ss.Dictionary$2,[g,e]))(null,f);this.forEach(function(b){d.add(c(b),a(b))});return d};a.prototype.toJSONString=function(a,b){if(typeof JSON===f.Undefined||JSON.stringify==null)throw new Error("toJSONString can't find JSON.stringify. This works native JSON support Browser or include json2.js");return JSON.stringify(this.toArray(),a,b)};a.prototype.toJoinedString=function(a,b){if(a==null)a="";if(b==null)b=d.Identity;return this.select(b).toArray().join(a)};a.prototype.doAction=function(d){var e=this;d=b.createLambda(d);return new a(function(){var a,f=0;return new c(function(){a=e.getEnumerator()},function(){if(a.moveNext()){d(a.current(),f++);return this.yieldReturn(a.current())}return false},function(){b.dispose(a)})})};a.prototype.forEach=function(c){c=b.createLambda(c);var d=0,a=this.getEnumerator();try{while(a.moveNext())if(c(a.current(),d++)===false)break}finally{b.dispose(a)}};a.prototype.write=function(a,c){if(a==null)a="";c=b.createLambda(c);var d=true;this.forEach(function(b){if(d)d=false;else document.write(a);document.write(c(b))})};a.prototype.writeLine=function(a){a=b.createLambda(a);this.forEach(function(b){document.writeln(a(b)+"<br />")})};a.prototype.force=function(){var a=this.getEnumerator();try{while(a.moveNext());}finally{b.dispose(a)}};a.prototype.letBind=function(d){d=b.createLambda(d);var e=this;return new a(function(){var f;return new c(function(){f=a.from(d(e)).getEnumerator()},function(){return f.moveNext()?this.yieldReturn(f.current()):false},function(){b.dispose(f)})})};a.prototype.share=function(){var f=this,a,e=false;return new n(function(){return new c(function(){if(a==null)a=f.getEnumerator()},function(){if(e)throw new Error("enumerator is disposed");return a.moveNext()?this.yieldReturn(a.current()):false},d.Blank)},function(){e=true;b.dispose(a)})};a.prototype.memoize=function(){var g=this,e,a,f=false;return new n(function(){var b=-1;return new c(function(){if(a==null){a=g.getEnumerator();e=[]}},function(){if(f)throw new Error("enumerator is disposed");b++;return e.length<=b?a.moveNext()?this.yieldReturn(e[b]=a.current()):false:this.yieldReturn(e[b])},d.Blank)},function(){f=true;b.dispose(a);e=null})};a.prototype.catchError=function(d){d=b.createLambda(d);var e=this;return new a(function(){var a;return new c(function(){a=e.getEnumerator()},function(){try{return a.moveNext()?this.yieldReturn(a.current()):false}catch(b){d(b);return false}},function(){b.dispose(a)})})};a.prototype.finallyAction=function(d){d=b.createLambda(d);var e=this;return new a(function(){var a;return new c(function(){a=e.getEnumerator()},function(){return a.moveNext()?this.yieldReturn(a.current()):false},function(){try{b.dispose(a)}finally{d()}})})};a.prototype.log=function(a){a=b.createLambda(a);return this.doAction(function(b){typeof console!==f.Undefined&&console.log(a(b))})};a.prototype.trace=function(c,a){if(c==null)c="Trace";a=b.createLambda(a);return this.doAction(function(b){typeof console!==f.Undefined&&console.log(c,a(b))})};var h=function(f,a,d,c,e){this.source=f;this.keySelector=b.createLambda(a);this.comparer=d||ss.Comparer.def;this.descending=c;this.parent=e};h.prototype=new a;h.prototype.createOrderedEnumerable=function(a,c,b){return new h(this.source,a,c,b,this)};h.prototype.thenBy=function(a,b){return this.createOrderedEnumerable(a,b,false)};h.prototype.thenByDescending=function(a,b){return this.createOrderedEnumerable(a,b,true)};h.prototype.getEnumerator=function(){var f=this,b,a,e=0;return new c(function(){b=[];a=[];f.source.forEach(function(d,c){b.push(d);a.push(c)});var c=l.create(f,null);c.GenerateKeys(b);a.sort(function(a,b){return c.compare(a,b)})},function(){return e<a.length?this.yieldReturn(b[a[e++]]):false},d.Blank)};var l=function(a,c,b,d){this.keySelector=a;this.comparer=c;this.descending=b;this.child=d;this.keys=null};l.create=function(a,c){var b=new l(a.keySelector,a.comparer,a.descending,c);return a.parent!=null?l.create(a.parent,b):b};l.prototype.GenerateKeys=function(b){for(var d=b.length,e=this.keySelector,c=new Array(d),a=0;a<d;a++)c[a]=e(b[a]);this.keys=c;this.child!=null&&this.child.GenerateKeys(b)};l.prototype.compare=function(c,d){var a=this.comparer.compare(this.keys[c],this.keys[d]);return a==0?this.child!=null?this.child.compare(c,d):b.compare(c,d):this.descending?-a:a};var n=function(b,c){this.dispose=c;a.call(this,b)};n.prototype=new a;var e=function(a){this.getSource=function(){return a}};e.prototype=new a;e.prototype.any=function(b){return b==null?this.getSource().length>0:a.prototype.any.apply(this,arguments)};e.prototype.count=function(b){return b==null?this.getSource().length:a.prototype.count.apply(this,arguments)};e.prototype.elementAt=function(b){var c=this.getSource();return 0<=b&&b<c.length?c[b]:a.prototype.elementAt.apply(this,arguments)};e.prototype.elementAtOrDefault=function(b,a){if(a===g)a=null;var c=this.getSource();return 0<=b&&b<c.length?c[b]:a};e.prototype.first=function(c){var b=this.getSource();return c==null&&b.length>0?b[0]:a.prototype.first.apply(this,arguments)};e.prototype.firstOrDefault=function(d,b){if(b===g)b=null;if(d!=null)return a.prototype.firstOrDefault.apply(this,arguments);var c=this.getSource();return c.length>0?c[0]:b};e.prototype.last=function(c){var b=this.getSource();return c==null&&b.length>0?b[b.length-1]:a.prototype.last.apply(this,arguments)};e.prototype.lastOrDefault=function(d,b){if(b===g)b=null;if(d!=null)return a.prototype.lastOrDefault.apply(this,arguments);var c=this.getSource();return c.length>0?c[c.length-1]:b};e.prototype.skip=function(e){var b=this.getSource();return new a(function(){var a;return new c(function(){a=e<0?0:e},function(){return a<b.length?this.yieldReturn(b[a++]):false},d.Blank)})};e.prototype.takeExceptLast=function(a){if(a==null)a=1;return this.take(this.getSource().length-a)};e.prototype.takeFromLast=function(a){return this.skip(this.getSource().length-a)};e.prototype.reverse=function(){var b=this.getSource();return new a(function(){var a;return new c(function(){a=b.length},function(){return a>0?this.yieldReturn(b[--a]):false},d.Blank)})};e.prototype.sequenceEqual=function(b,c){return(b instanceof e||b instanceof Array)&&c==null&&a.from(b).count()!=this.count()?false:a.prototype.sequenceEqual.apply(this,arguments)};e.prototype.toJoinedString=function(b,d){var c=this.getSource();if(d!=null||!(c instanceof Array))return a.prototype.toJoinedString.apply(this,arguments);if(b==null)b="";return c.join(b)};e.prototype.getEnumerator=function(){return new ss.ArrayEnumerator(this.getSource())};var j=function(b,a){this.prevSource=b;this.prevPredicate=a};j.prototype=new a;j.prototype.where=function(c){c=b.createLambda(c);if(c.length<=1){var e=this.prevPredicate,d=function(a){return e(a)&&c(a)};return new j(this.prevSource,d)}else return a.prototype.where.call(this,c)};j.prototype.select=function(c){c=b.createLambda(c);return c.length<=1?new i(this.prevSource,this.prevPredicate,c):a.prototype.select.call(this,c)};j.prototype.getEnumerator=function(){var d=this.prevPredicate,e=this.prevSource,a;return new c(function(){a=e.getEnumerator()},function(){while(a.moveNext())if(d(a.current()))return this.yieldReturn(a.current());return false},function(){b.dispose(a)})};var i=function(c,a,b){this.prevSource=c;this.prevPredicate=a;this.prevSelector=b};i.prototype=new a;i.prototype.where=function(c){c=b.createLambda(c);return c.length<=1?new j(this,c):a.prototype.where.call(this,c)};i.prototype.select=function(c){c=b.createLambda(c);if(c.length<=1){var e=this.prevSelector,d=function(a){return c(e(a))};return new i(this.prevSource,this.prevPredicate,d)}else return a.prototype.select.call(this,c)};i.prototype.getEnumerator=function(){var d=this.prevPredicate,e=this.prevSelector,f=this.prevSource,a;return new c(function(){a=f.getEnumerator()},function(){while(a.moveNext())if(d==null||d(a.current()))return this.yieldReturn(e(a.current()));return false},function(){b.dispose(a)})};var p=function(b,c){this.count=function(){return b.get_count()};this.get=function(e){var c={$:null},d=b.tryGetValue(e,c);return a.from(d?c.$:[])};this.contains=function(a){return b.containsKey(a)};this.toEnumerable=function(){return a.from(c).select(function(a){return new o(a,b.get_item(a))})};this.getEnumerator=function(){return this.toEnumerable().getEnumerator()}};ss.initClass(p,m,{},null,[ss.IEnumerable]);var o=function(b,a){this.key=function(){return b};e.call(this,a)};o.prototype=new e;if(typeof define===f.Function&&define.amd){define("linqjs",[],function(){return a});q.Enumerable=a}else if(typeof module!==f.Undefined&&module.exports){module.exports=a;global.Enumerable=a}else q.Enumerable=a})(this)
Note: See TracBrowser for help on using the repository browser.