You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1 lines
39 KiB

var Functions={Identity:function(e){return e},True:function(){return!0},Blank:function(){}},Types={Boolean:typeof!0,Number:"number",String:"string",Object:typeof{},Undefined:"undefined",Function:"function"},funcCache={"":Functions.Identity},Utils={createLambda:function(n){if(null==n)return Functions.Identity;if(typeof n!==Types.String)return n;{let t=funcCache[n];if(null!=t)return t;if(-1===n.indexOf("=>")){const o=new RegExp("[$]+","g");let e=0;for(var r;null!=(r=o.exec(n));)r[0].length>e&&(e=r[0].length);const i=[];for(let n=1;n<=e;n++){let t="";for(let e=0;e<n;e++)t+="$";i.push(t)}var u=i.join(",");return t=new Function(u,"return "+n),funcCache[n]=t,t}{const e=n.match(/^[(\s]*([^()]*?)[)\s]*=>(.*)/);return t=new Function(e[1],e[2].match(/\breturn\b/)?e[2]:"return "+e[2]),funcCache[n]=t,t}}},defineProperty:function(e,t,n){Object.defineProperty(e,t,{enumerable:!1,configurable:!0,writable:!0,value:n})},compare:function(e,t){return e===t?0:t<e?1:-1},dispose:function(e){null!=e&&e.dispose()},hasNativeIteratorSupport:function(){return"undefined"!=typeof Symbol&&void 0!==Symbol.iterator}},State={Before:0,Running:1,After:2},IEnumerator=function(e,t,n){var r=new Yielder,u=State.Before;this.current=r.current,this.moveNext=function(){try{switch(u){case State.Before:u=State.Running,e();case State.Running:return!!t.apply(r)||(this.dispose(),!1);case State.After:return!1}}catch(e){throw this.dispose(),e}},this.dispose=function(){if(u==State.Running)try{n()}finally{u=State.After}}},Yielder=function(){var t=null;this.current=function(){return t},this.yieldReturn=function(e){return t=e,!0},this.yieldBreak=function(){return!1}},Enumerable=function(e){this.getEnumerator=e};Enumerable.Utils={},Enumerable.Utils.createLambda=function(e){return Utils.createLambda(e)},Enumerable.Utils.createEnumerable=function(e){return new Enumerable(e)},Enumerable.Utils.createEnumerator=function(e,t,n){return new IEnumerator(e,t,n)},Enumerable.Utils.extendTo=function(e){var t,n,r=e.prototype;for(n in e===Array?(t=ArrayEnumerable.prototype,Utils.defineProperty(r,"getSource",function(){return this})):(t=Enumerable.prototype,Utils.defineProperty(r,"getEnumerator",function(){return Enumerable.from(this).getEnumerator()})),t){var u=t[n];r[n]!=u&&(null!=r[n]&&(n+="ByLinq",r[n]==u)||u instanceof Function&&Utils.defineProperty(r,n,u))}},Enumerable.Utils.recallFrom=function(e){var t,n=e.prototype;e===Array?(t=ArrayEnumerable.prototype,delete n.getSource):(t=Enumerable.prototype,delete n.getEnumerator);for(const u in t){var r=t[u];n[u+"ByLinq"]?delete n[u+"ByLinq"]:n[u]==r&&r instanceof Function&&delete n[u]}},Enumerable.choice=function(){var e=arguments;return new Enumerable(function(){return new IEnumerator(function(){e=e[0]instanceof Array?e[0]:null!=e[0].getEnumerator?e[0].toArray():e},function(){return this.yieldReturn(e[Math.floor(Math.random()*e.length)])},Functions.Blank)})},Enumerable.cycle=function(){var t=arguments;return new Enumerable(function(){var e=0;return new IEnumerator(function(){t=t[0]instanceof Array?t[0]:null!=t[0].getEnumerator?t[0].toArray():t},function(){return e>=t.length&&(e=0),this.yieldReturn(t[e++])},Functions.Blank)})},Enumerable.empty=function(){return new Enumerable(function(){return new IEnumerator(Functions.Blank,function(){return!1},Functions.Blank)})},Enumerable.from=function(r){if(null==r)return Enumerable.empty();if(r instanceof Enumerable)return r;if(typeof r==Types.Number||typeof r==Types.Boolean)return Enumerable.repeat(r,1);if(typeof r==Types.String)return new Enumerable(function(){var e=0;return new IEnumerator(Functions.Blank,function(){return e<r.length&&this.yieldReturn(r.charAt(e++))},Functions.Blank)});if(typeof r!=Types.Function){if(typeof r.length==Types.Number)return new ArrayEnumerable(r);if("undefined"!=typeof Symbol&&void 0!==r[Symbol.iterator])return new Enumerable(function(){return new IEnumerator(Functions.Blank,function(){var e=r.next();return!e.done&&this.yieldReturn(e.value)},Functions.Blank)})}return new Enumerable(function(){var n=[],e=0;return new IEnumerator(function(){for(const t in r){var e=r[t];e instanceof Function||!Object.prototype.hasOwnProperty.call(r,t)||n.push({key:t,value:e})}},function(){return e<n.length&&this.yieldReturn(n[e++])},Functions.Blank)})},Enumerable.make=function(e){return Enumerable.repeat(e,1)},Enumerable.matches=function(n,e,r){return null==r&&(r=""),e instanceof RegExp&&(r+=e.ignoreCase?"i":"",r+=e.multiline?"m":"",e=e.source),-1===r.indexOf("g")&&(r+="g"),new Enumerable(function(){var t;return new IEnumerator(function(){t=new RegExp(e,r)},function(){var e=t.exec(n);return!!e&&this.yieldReturn(e)},Functions.Blank)})},Enumerable.range=function(n,r,u){return null==u&&(u=1),new Enumerable(function(){var e,t=0;return new IEnumerator(function(){e=n-u},function(){return t++<r?this.yieldReturn(e+=u):this.yieldBreak()},Functions.Blank)})},Enumerable.rangeDown=function(n,r,u){return null==u&&(u=1),new Enumerable(function(){var e,t=0;return new IEnumerator(function(){e=n+u},function(){return t++<r?this.yieldReturn(e-=u):this.yieldBreak()},Functions.Blank)})},Enumerable.rangeTo=function(e,n,r){return null==r&&(r=1),new Enumerable(e<n?function(){var t;return new IEnumerator(function(){t=e-r},function(){var e=t+=r;return e<=n?this.yieldReturn(e):this.yieldBreak()},Functions.Blank)}:function(){var t;return new IEnumerator(function(){t=e+r},function(){var e=t-=r;return n<=e?this.yieldReturn(e):this.yieldBreak()},Functions.Blank)})},Enumerable.repeat=function(e,t){return null!=t?Enumerable.repeat(e).take(t):new Enumerable(function(){return new IEnumerator(Functions.Blank,function(){return this.yieldReturn(e)},Functions.Blank)})},Enumerable.repeatWithFinalize=function(t,n){return t=Utils.createLambda(t),n=Utils.createLambda(n),new Enumerable(function(){var e;return new IEnumerator(function(){e=t()},function(){return this.yieldReturn(e)},function(){null!=e&&(n(e),e=null)})})},Enumerable.generate=function(e,t){return null!=t?Enumerable.generate(e).take(t):(e=Utils.createLambda(e),new Enumerable(function(){return new IEnumerator(Functions.Blank,function(){return this.yieldReturn(e())},Functions.Blank)}))},Enumerable.toInfinity=function(t,n){return null==t&&(t=0),null==n&&(n=1),new Enumerable(function(){var e;return new IEnumerator(function(){e=t-n},function(){return this.yieldReturn(e+=n)},Functions.Blank)})},Enumerable.toNegativeInfinity=function(t,n){return null==t&&(t=0),null==n&&(n=1),new Enumerable(function(){var e;return new IEnumerator(function(){e=t+n},function(){return this.yieldReturn(e-=n)},Functions.Blank)})},Enumerable.unfold=function(n,r){return r=Utils.createLambda(r),new Enumerable(function(){var e,t=!0;return new IEnumerator(Functions.Blank,function(){return e=t?(t=!1,n):r(e),this.yieldReturn(e)},Functions.Blank)})},Enumerable.defer=function(t){return new Enumerable(function(){var e;return new IEnumerator(function(){e=Enumerable.from(t()).getEnumerator()},function(){return e.moveNext()?this.yieldReturn(e.current()):this.yieldBreak()},function(){Utils.dispose(e)})})},Enumerable.prototype.traverseBreadthFirst=function(u,o){var e=this;return u=Utils.createLambda(u),o=Utils.createLambda(o),new Enumerable(function(){var t,n=0,r=[];return new IEnumerator(function(){t=e.getEnumerator()},function(){for(;;){if(t.moveNext())return r.push(t.current()),this.yieldReturn(o(t.current(),n));const e=Enumerable.from(r).selectMany(function(e){return u(e)});if(!e.any())return!1;n++,r=[],Utils.dispose(t),t=e.getEnumerator()}},function(){Utils.dispose(t)})})},Enumerable.prototype.traverseDepthFirst=function(r,u){var e=this;return r=Utils.createLambda(r),u=Utils.createLambda(u),new Enumerable(function(){var t,n=[];return new IEnumerator(function(){t=e.getEnumerator()},function(){for(;;){if(t.moveNext()){var e=u(t.current(),n.length);return n.push(t),t=Enumerable.from(r(t.current())).getEnumerator(),this.yieldReturn(e)}if(n.length<=0)return!1;Utils.dispose(t),t=n.pop()}},function(){try{Utils.dispose(t)}finally{Enumerable.from(n).forEach(function(e){e.dispose()})}})})},Enumerable.prototype.flatten=function(){var n=this;return new Enumerable(function(){var e,t=null;return new IEnumerator(function(){e=n.getEnumerator()},function(){for(;;){if(null!=t){if(t.moveNext())return this.yieldReturn(t.current());t=null}if(e.moveNext()){if(e.current()instanceof Array){Utils.dispose(t),t=Enumerable.from(e.current()).selectMany(Functions.Identity).flatten().getEnumerator();continue}return this.yieldReturn(e.current())}return!1}},function(){try{Utils.dispose(e)}finally{Utils.dispose(t)}})})},Enumerable.prototype.pairwise=function(n){var e=this;return n=Utils.createLambda(n),new Enumerable(function(){var t;return new IEnumerator(function(){(t=e.getEnumerator()).moveNext()},function(){var e=t.current();return!!t.moveNext()&&this.yieldReturn(n(e,t.current()))},function(){Utils.dispose(t)})})},Enumerable.prototype.scan=function(r,u){var o=null==u?(u=Utils.createLambda(r),!1):(u=Utils.createLambda(u),!0),i=this;return new Enumerable(function(){var e,t,n=!0;return new IEnumerator(function(){e=i.getEnumerator()},function(){if(n){if(n=!1,o)return this.yieldReturn(t=r);if(e.moveNext())return this.yieldReturn(t=e.current())}return!!e.moveNext()&&this.yieldReturn(t=u(t,e.current()))},function(){Utils.dispose(e)})})},Enumerable.prototype.select=function(n){if((n=Utils.createLambda(n)).length<=1)return new WhereSelectEnumerable(this,null,n);var r=this;return new Enumerable(function(){var e,t=0;return new IEnumerator(function(){e=r.getEnumerator()},function(){return!!e.moveNext()&&this.yieldReturn(n(e.current(),t++))},function(){Utils.dispose(e)})})},Enumerable.prototype.selectMany=function(u,o){var e=this;return u=Utils.createLambda(u),null==o&&(o=function(e,t){return t}),o=Utils.createLambda(o),new Enumerable(function(){var t,n=void 0,r=0;return new IEnumerator(function(){t=e.getEnumerator()},function(){if(void 0===n&&!t.moveNext())return!1;do{var e;if(null==n&&(e=u(t.current(),r++),n=Enumerable.from(e).getEnumerator()),n.moveNext())return this.yieldReturn(o(t.current(),n.current()))}while(Utils.dispose(n),n=null,t.moveNext());return!1},function(){try{Utils.dispose(t)}finally{Utils.dispose(n)}})})},Enumerable.prototype.where=function(n){if((n=Utils.createLambda(n)).length<=1)return new WhereEnumerable(this,n);var r=this;return new Enumerable(function(){var e,t=0;return new IEnumerator(function(){e=r.getEnumerator()},function(){for(;e.moveNext();)if(n(e.current(),t++))return this.yieldReturn(e.current());return!1},function(){Utils.dispose(e)})})},Enumerable.prototype.choose=function(r){r=Utils.createLambda(r);var e=this;return new Enumerable(function(){var t,n=0;return new IEnumerator(function(){t=e.getEnumerator()},function(){for(;t.moveNext();){var e=r(t.current(),n++);if(null!=e)return this.yieldReturn(e)}return this.yieldBreak()},function(){Utils.dispose(t)})})},Enumerable.prototype.ofType=function(t){var n;switch(t){case Number:n=Types.Number;break;case String:n=Types.String;break;case Boolean:n=Types.Boolean;break;case Function:n=Types.Function;break;default:n=null}return null===n?this.where(function(e){return e instanceof t}):this.where(function(e){return typeof e===n})},Enumerable.prototype.zip=function(){var r=arguments,u=Utils.createLambda(arguments[arguments.length-1]),o=this;if(2!=arguments.length)return new Enumerable(function(){var t,n=0;return new IEnumerator(function(){var e=Enumerable.make(o).concat(Enumerable.from(r).takeExceptLast().select(Enumerable.from)).select(function(e){return e.getEnumerator()}).toArray();t=Enumerable.from(e)},function(){if(t.all(function(e){return e.moveNext()})){const e=t.select(function(e){return e.current()}).toArray();return e.push(n++),this.yieldReturn(u.apply(null,e))}return this.yieldBreak()},function(){Enumerable.from(t).forEach(Utils.dispose)})});{const i=arguments[0];return new Enumerable(function(){var e,t,n=0;return new IEnumerator(function(){e=o.getEnumerator(),t=Enumerable.from(i).getEnumerator()},function(){return!(!e.moveNext()||!t.moveNext())&&this.yieldReturn(u(e.current(),t.current(),n++))},function(){try{Utils.dispose(e)}finally{Utils.dispose(t)}})})}},Enumerable.prototype.merge=function(){var e=arguments,r=this;return new Enumerable(function(){var t,n=-1;return new IEnumerator(function(){t=Enumerable.make(r).concat(Enumerable.from(e).select(Enumerable.from)).select(function(e){return e.getEnumerator()}).toArray()},function(){for(;0<t.length;){n=n>=t.length-1?0:n+1;const e=t[n];if(e.moveNext())return this.yieldReturn(e.current());e.dispose(),t.splice(n--,1)}return this.yieldBreak()},function(){Enumerable.from(t).forEach(Utils.dispose)})})},Enumerable.prototype.join=function(e,o,i,a,l){o=Utils.createLambda(o),i=Utils.createLambda(i),a=Utils.createLambda(a),l=Utils.createLambda(l);var c=this;return new Enumerable(function(){var t,n,r=null,u=0;return new IEnumerator(function(){t=c.getEnumerator(),n=Enumerable.from(e).toLookup(i,Functions.Identity,l)},function(){for(;;){if(null!=r){let e=r[u++];if(void 0!==e)return this.yieldReturn(a(t.current(),e));e=null,u=0}if(!t.moveNext())return!1;var e=o(t.current());r=n.get(e).toArray()}},function(){Utils.dispose(t)})})},Enumerable.prototype.leftJoin=function(e,o,i,a,l){o=Utils.createLambda(o),i=Utils.createLambda(i),a=Utils.createLambda(a),l=Utils.createLambda(l);var c=this;return new Enumerable(function(){var t,n,r=null,u=0;return new IEnumerator(function(){t=c.getEnumerator(),n=Enumerable.from(e).toLookup(i,Functions.Identity,l)},function(){for(;;){if(null!=r){let e=r[u++];if(void 0!==e)return this.yieldReturn(a(t.current(),e));e=null,u=0}if(!t.moveNext())return!1;var e=o(t.current());if(null==(r=n.get(e).toArray())||0==r.length)return this.yieldReturn(a(t.current(),null))}},function(){Utils.dispose(t)})})},Enumerable.prototype.groupJoin=function(e,r,u,o,i){r=Utils.createLambda(r),u=Utils.createLambda(u),o=Utils.createLambda(o),i=Utils.createLambda(i);var a=this;return new Enumerable(function(){var t=a.getEnumerator(),n=null;return new IEnumerator(function(){t=a.getEnumerator(),n=Enumerable.from(e).toLookup(u,Functions.Identity,i)},function(){if(t.moveNext()){var e=n.get(r(t.current()));return this.yieldReturn(o(t.current(),e))}return!1},function(){Utils.dispose(t)})})},Enumerable.prototype.all=function(t){t=Utils.createLambda(t);var n=!0;return this.forEach(function(e){if(!t(e))return n=!1}),n},Enumerable.prototype.any=function(e){e=Utils.createLambda(e);var t=this.getEnumerator();try{if(0==arguments.length)return t.moveNext();for(;t.moveNext();)if(e(t.current()))return!0;return!1}finally{Utils.dispose(t)}},Enumerable.prototype.isEmpty=function(){return!this.any()},Enumerable.prototype.concat=function(){var n=this;if(1==arguments.length){const r=arguments[0];return new Enumerable(function(){var e,t;return new IEnumerator(function(){e=n.getEnumerator()},function(){if(null==t){if(e.moveNext())return this.yieldReturn(e.current());t=Enumerable.from(r).getEnumerator()}return!!t.moveNext()&&this.yieldReturn(t.current())},function(){try{Utils.dispose(e)}finally{Utils.dispose(t)}})})}{const e=arguments;return new Enumerable(function(){var t;return new IEnumerator(function(){t=Enumerable.make(n).concat(Enumerable.from(e).select(Enumerable.from)).select(function(e){return e.getEnumerator()}).toArray()},function(){for(;0<t.length;){const e=t[0];if(e.moveNext())return this.yieldReturn(e.current());e.dispose(),t.splice(0,1)}return this.yieldBreak()},function(){Enumerable.from(t).forEach(Utils.dispose)})})}},Enumerable.prototype.insert=function(u,o){var i=this;return new Enumerable(function(){var e,t,n=0,r=!1;return new IEnumerator(function(){e=i.getEnumerator(),t=Enumerable.from(o).getEnumerator()},function(){return n==u&&t.moveNext()?(r=!0,this.yieldReturn(t.current())):e.moveNext()?(n++,this.yieldReturn(e.current())):!(r||!t.moveNext())&&this.yieldReturn(t.current())},function(){try{Utils.dispose(e)}finally{Utils.dispose(t)}})})},Enumerable.prototype.alternate=function(e){var o=this;return new Enumerable(function(){var t,n,r,u;return new IEnumerator(function(){r=e instanceof Array||null!=e.getEnumerator?Enumerable.from(Enumerable.from(e).toArray()):Enumerable.make(e),(n=o.getEnumerator()).moveNext()&&(t=n.current())},function(){for(;;){if(null!=u){if(u.moveNext())return this.yieldReturn(u.current());u=null}if(null!=t||!n.moveNext()){if(null==t)return this.yieldBreak();var e=t;return t=null,this.yieldReturn(e)}t=n.current(),u=r.getEnumerator()}},function(){try{Utils.dispose(n)}finally{Utils.dispose(u)}})})},Enumerable.prototype.contains=function(e,t){t=Utils.createLambda(t);var n=this.getEnumerator();try{for(;n.moveNext();)if(t(n.current())===e)return!0;return!1}finally{Utils.dispose(n)}},Enumerable.prototype.defaultIfEmpty=function(n){var r=this;return void 0===n&&(n=null),new Enumerable(function(){var e,t=!0;return new IEnumerator(function(){e=r.getEnumerator()},function(){return e.moveNext()?(t=!1,this.yieldReturn(e.current())):!!t&&(t=!1,this.yieldReturn(n))},function(){Utils.dispose(e)})})},Enumerable.prototype.distinct=function(e){return this.except(Enumerable.empty(),e)},Enumerable.prototype.distinctUntilChanged=function(u){u=Utils.createLambda(u);var e=this;return new Enumerable(function(){var t,n,r;return new IEnumerator(function(){t=e.getEnumerator()},function(){for(;t.moveNext();){var e=u(t.current());if(r)return r=!1,n=e,this.yieldReturn(t.current());if(n!==e)return n=e,this.yieldReturn(t.current())}return this.yieldBreak()},function(){Utils.dispose(t)})})},Enumerable.prototype.except=function(e,r){r=Utils.createLambda(r);var u=this;return new Enumerable(function(){var t,n;return new IEnumerator(function(){t=u.getEnumerator(),n=new Dictionary(r),Enumerable.from(e).forEach(function(e){n.add(e)})},function(){for(;t.moveNext();){var e=t.current();if(!n.contains(e))return n.add(e),this.yieldReturn(e)}return!1},function(){Utils.dispose(t)})})},Enumerable.prototype.intersect=function(e,u){u=Utils.createLambda(u);var o=this;return new Enumerable(function(){var t,n,r;return new IEnumerator(function(){t=o.getEnumerator(),n=new Dictionary(u),Enumerable.from(e).forEach(function(e){n.add(e)}),r=new Dictionary(u)},function(){for(;t.moveNext();){var e=t.current();if(!r.contains(e)&&n.contains(e))return r.add(e),this.yieldReturn(e)}return!1},function(){Utils.dispose(t)})})},Enumerable.prototype.sequenceEqual=function(e,t){t=Utils.createLambda(t);var n=this.getEnumerator();try{const r=Enumerable.from(e).getEnumerator();try{for(;n.moveNext();)if(!r.moveNext()||t(n.current())!==t(r.current()))return!1;return r.moveNext()?!1:!0}finally{Utils.dispose(r)}}finally{Utils.dispose(n)}},Enumerable.prototype.union=function(u,e){e=Utils.createLambda(e);var o=this;return new Enumerable(function(){var t,n,r;return new IEnumerator(function(){t=o.getEnumerator(),r=new Dictionary(e)},function(){var e;if(void 0===n){for(;t.moveNext();)if(e=t.current(),!r.contains(e))return r.add(e),this.yieldReturn(e);n=Enumerable.from(u).getEnumerator()}for(;n.moveNext();)if(e=n.current(),!r.contains(e))return r.add(e),this.yieldReturn(e);return!1},function(){try{Utils.dispose(t)}finally{Utils.dispose(n)}})})},Enumerable.prototype.orderBy=function(e,t){return new OrderedEnumerable(this,e,t,!1)},Enumerable.prototype.orderByDescending=function(e,t){return new OrderedEnumerable(this,e,t,!0)},Enumerable.prototype.reverse=function(){var n=this;return new Enumerable(function(){var e,t;return new IEnumerator(function(){e=n.toArray(),t=e.length},function(){return 0<t&&this.yieldReturn(e[--t])},Functions.Blank)})},Enumerable.prototype.shuffle=function(){var e=this;return new Enumerable(function(){var t;return new IEnumerator(function(){t=e.toArray()},function(){if(0<t.length){var e=Math.floor(Math.random()*t.length);return this.yieldReturn(t.splice(e,1)[0])}return!1},Functions.Blank)})},Enumerable.prototype.weightedSample=function(n){n=Utils.createLambda(n);var e=this;return new Enumerable(function(){var u,o=0;return new IEnumerator(function(){u=e.choose(function(e){var t=n(e);return t<=0?null:{value:e,bound:o+=t}}).toArray()},function(){if(0<u.length){var n=Math.floor(Math.random()*o)+1;let e=-1,t=u.length;for(;1<t-e;){var r=Math.floor((e+t)/2);u[r].bound>=n?t=r:e=r}return this.yieldReturn(u[t].value)}return this.yieldBreak()},Functions.Blank)})},Enumerable.prototype.groupBy=function(t,n,r,u){var o=this;return t=Utils.createLambda(t),n=Utils.createLambda(n),null!=r&&(r=Utils.createLambda(r)),u=Utils.createLambda(u),new Enumerable(function(){var e;return new IEnumerator(function(){e=o.toLookup(t,n,u).toEnumerable().getEnumerator()},function(){return!!e.moveNext()&&(null==r?this.yieldReturn(e.current()):this.yieldReturn(r(e.current().key(),e.current())))},function(){Utils.dispose(e)})})},Enumerable.prototype.partitionBy=function(i,a,l,c){var s,e=this;return i=Utils.createLambda(i),a=Utils.createLambda(a),c=Utils.createLambda(c),l=null==l?(s=!1,function(e,t){return new Grouping(e,t)}):(s=!0,Utils.createLambda(l)),new Enumerable(function(){var n,r,u,o=[];return new IEnumerator(function(){(n=e.getEnumerator()).moveNext()&&(r=i(n.current()),u=c(r),o.push(a(n.current())))},function(){for(var e;1==(e=n.moveNext())&&u===c(i(n.current()));)o.push(a(n.current()));if(0<o.length){var t=l(r,s?Enumerable.from(o):o);return o=e?(r=i(n.current()),u=c(r),[a(n.current())]):[],this.yieldReturn(t)}return!1},function(){Utils.dispose(n)})})},Enumerable.prototype.buffer=function(r){var e=this;return new Enumerable(function(){var n;return new IEnumerator(function(){n=e.getEnumerator()},function(){for(var e=[],t=0;n.moveNext();)if(e.push(n.current()),++t>=r)return this.yieldReturn(e);return 0<e.length&&this.yieldReturn(e)},function(){Utils.dispose(n)})})},Enumerable.prototype.aggregate=function(e,t,n){return(n=Utils.createLambda(n))(this.scan(e,t,n).last())},Enumerable.prototype.average=function(t){t=Utils.createLambda(t);var n=0,r=0;return this.forEach(function(e){n+=t(e),++r}),n/r},Enumerable.prototype.count=function(n){n=null==n?Functions.True:Utils.createLambda(n);var r=0;return this.forEach(function(e,t){n(e,t)&&++r}),r},Enumerable.prototype.max=function(e){return null==e&&(e=Functions.Identity),this.select(e).aggregate(function(e,t){return t<e?e:t})},Enumerable.prototype.min=function(e){return null==e&&(e=Functions.Identity),this.select(e).aggregate(function(e,t){return e<t?e:t})},Enumerable.prototype.maxBy=function(n){return n=Utils.createLambda(n),this.aggregate(function(e,t){return n(e)>n(t)?e:t})},Enumerable.prototype.minBy=function(n){return n=Utils.createLambda(n),this.aggregate(function(e,t){return n(e)<n(t)?e:t})},Enumerable.prototype.sum=function(e){return null==e&&(e=Functions.Identity),this.select(e).aggregate(0,function(e,t){return e+t})},Enumerable.prototype.elementAt=function(n){var r,u=!1;if(this.forEach(function(e,t){if(t==n)return r=e,!(u=!0)}),!u)throw new Error("index is less than 0 or greater than or equal to the number of elements in source.");return r},Enumerable.prototype.elementAtOrDefault=function(n,e){var r;void 0===e&&(e=null);var u=!1;return this.forEach(function(e,t){if(t==n)return r=e,!(u=!0)}),u?r:e},Enumerable.prototype.first=function(e){if(null!=e)return this.where(e).first();var t,n=!1;if(this.forEach(function(e){return t=e,!(n=!0)}),!n)throw new Error("first:No element satisfies the condition.");return t},Enumerable.prototype.firstOrDefault=function(e,t){if(void 0!==e){if(typeof e===Types.Function||typeof Utils.createLambda(e)===Types.Function)return this.where(e).firstOrDefault(void 0,t);t=e}var n,r=!1;return this.forEach(function(e){return n=e,!(r=!0)}),r?n:t},Enumerable.prototype.last=function(e){if(null!=e)return this.where(e).last();var t,n=!1;if(this.forEach(function(e){n=!0,t=e}),!n)throw new Error("last:No element satisfies the condition.");return t},Enumerable.prototype.lastOrDefault=function(e,t){if(void 0!==e){if(typeof e===Types.Function||typeof Utils.createLambda(e)===Types.Function)return this.where(e).lastOrDefault(void 0,t);t=e}var n,r=!1;return this.forEach(function(e){r=!0,n=e}),r?n:t},Enumerable.prototype.single=function(e){if(null!=e)return this.where(e).single();var t,n=!1;if(this.forEach(function(e){if(n)throw new Error("single:sequence contains more than one element.");n=!0,t=e}),!n)throw new Error("single:No element satisfies the condition.");return t},Enumerable.prototype.singleOrDefault=function(e,t){if(void 0===t&&(t=null),null!=e)return this.where(e).singleOrDefault(null,t);var n,r=!1;return this.forEach(function(e){if(r)throw new Error("single:sequence contains more than one element.");r=!0,n=e}),r?n:t},Enumerable.prototype.skip=function(n){var r=this;return new Enumerable(function(){var e,t=0;return new IEnumerator(function(){for(e=r.getEnumerator();t++<n&&e.moveNext(););},function(){return!!e.moveNext()&&this.yieldReturn(e.current())},function(){Utils.dispose(e)})})},Enumerable.prototype.skipWhile=function(r){r=Utils.createLambda(r);var u=this;return new Enumerable(function(){var e,t=0,n=!1;return new IEnumerator(function(){e=u.getEnumerator()},function(){for(;!n;){if(!e.moveNext())return!1;if(!r(e.current(),t++))return n=!0,this.yieldReturn(e.current())}return!!e.moveNext()&&this.yieldReturn(e.current())},function(){Utils.dispose(e)})})},Enumerable.prototype.take=function(n){var r=this;return new Enumerable(function(){var e,t=0;return new IEnumerator(function(){e=r.getEnumerator()},function(){return!!(t++<n&&e.moveNext())&&this.yieldReturn(e.current())},function(){Utils.dispose(e)})})},Enumerable.prototype.takeWhile=function(n){n=Utils.createLambda(n);var r=this;return new Enumerable(function(){var e,t=0;return new IEnumerator(function(){e=r.getEnumerator()},function(){return!(!e.moveNext()||!n(e.current(),t++))&&this.yieldReturn(e.current())},function(){Utils.dispose(e)})})},Enumerable.prototype.takeExceptLast=function(n){null==n&&(n=1);var r=this;return new Enumerable(function(){if(n<=0)return r.getEnumerator();var e,t=[];return new IEnumerator(function(){e=r.getEnumerator()},function(){for(;e.moveNext();){if(t.length==n)return t.push(e.current()),this.yieldReturn(t.shift());t.push(e.current())}return!1},function(){Utils.dispose(e)})})},Enumerable.prototype.takeFromLast=function(r){if(r<=0||null==r)return Enumerable.empty();var u=this;return new Enumerable(function(){var e,t,n=[];return new IEnumerator(function(){e=u.getEnumerator()},function(){for(;e.moveNext();)n.length==r&&n.shift(),n.push(e.current());return!!(t=null==t?Enumerable.from(n).getEnumerator():t).moveNext()&&this.yieldReturn(t.current())},function(){Utils.dispose(t)})})},Enumerable.prototype.indexOf=function(n){var r=null;return typeof n===Types.Function?this.forEach(function(e,t){if(n(e,t))return r=t,!1}):this.forEach(function(e,t){if(e===n)return r=t,!1}),null!==r?r:-1},Enumerable.prototype.lastIndexOf=function(n){var r=-1;return typeof n===Types.Function?this.forEach(function(e,t){n(e,t)&&(r=t)}):this.forEach(function(e,t){e===n&&(r=t)}),r},Enumerable.prototype.cast=function(){return this},Enumerable.prototype.asEnumerable=function(){return Enumerable.from(this)},Enumerable.prototype.toArray=function(){var t=[];return this.forEach(function(e){t.push(e)}),t},Enumerable.prototype.toLookup=function(r,u,e){r=Utils.createLambda(r),u=Utils.createLambda(u),e=Utils.createLambda(e);var o=new Dictionary(e);return this.forEach(function(e){var t=r(e),n=u(e),e=o.get(t);void 0!==e?e.push(n):o.add(t,[n])}),new Lookup(o)},Enumerable.prototype.toObject=function(t,n){t=Utils.createLambda(t),n=Utils.createLambda(n);var r={};return this.forEach(function(e){r[t(e)]=n(e)}),r},Enumerable.prototype.toDictionary=function(t,n,e){t=Utils.createLambda(t),n=Utils.createLambda(n),e=Utils.createLambda(e);var r=new Dictionary(e);return this.forEach(function(e){r.add(t(e),n(e))}),r},Enumerable.prototype.toJSONString=function(e,t){if(typeof JSON===Types.Undefined||null==JSON.stringify)throw new Error("toJSONString can't find JSON.stringify. This works native JSON support Browser or include json2.js");return JSON.stringify(this.toArray(),e,t)},Enumerable.prototype.toJoinedString=function(e,t){return null==e&&(e=""),null==t&&(t=Functions.Identity),this.select(t).toArray().join(e)},Enumerable.prototype.doAction=function(n){var r=this;return n=Utils.createLambda(n),new Enumerable(function(){var e,t=0;return new IEnumerator(function(){e=r.getEnumerator()},function(){return!!e.moveNext()&&(n(e.current(),t++),this.yieldReturn(e.current()))},function(){Utils.dispose(e)})})},Enumerable.prototype.forEach=function(e){e=Utils.createLambda(e);var t=0,n=this.getEnumerator();try{for(;n.moveNext()&&!1!==e(n.current(),t++););}finally{Utils.dispose(n)}},Enumerable.prototype.force=function(){var e=this.getEnumerator();try{for(;e.moveNext(););}finally{Utils.dispose(e)}},Enumerable.prototype.letBind=function(t){t=Utils.createLambda(t);var n=this;return new Enumerable(function(){var e;return new IEnumerator(function(){e=Enumerable.from(t(n)).getEnumerator()},function(){return!!e.moveNext()&&this.yieldReturn(e.current())},function(){Utils.dispose(e)})})},Enumerable.prototype.share=function(){var e,t=this,n=!1;return new DisposableEnumerable(function(){return new IEnumerator(function(){null==e&&(e=t.getEnumerator())},function(){if(n)throw new Error("enumerator is disposed");return!!e.moveNext()&&this.yieldReturn(e.current())},Functions.Blank)},function(){n=!0,Utils.dispose(e)})},Enumerable.prototype.memoize=function(){var t,n,r=this,u=!1;return new DisposableEnumerable(function(){var e=-1;return new IEnumerator(function(){null==n&&(n=r.getEnumerator(),t=[])},function(){if(u)throw new Error("enumerator is disposed");return e++,t.length<=e?!!n.moveNext()&&this.yieldReturn(t[e]=n.current()):this.yieldReturn(t[e])},Functions.Blank)},function(){u=!0,Utils.dispose(n),t=null})},Utils.hasNativeIteratorSupport()&&(Enumerable.prototype[Symbol.iterator]=function(){return{enumerator:this.getEnumerator(),next:function(){return this.enumerator.moveNext()?{done:!1,value:this.enumerator.current()}:{done:!0}}}}),Enumerable.prototype.catchError=function(t){t=Utils.createLambda(t);var n=this;return new Enumerable(function(){var e;return new IEnumerator(function(){e=n.getEnumerator()},function(){try{return!!e.moveNext()&&this.yieldReturn(e.current())}catch(e){return t(e),!1}},function(){Utils.dispose(e)})})},Enumerable.prototype.finallyAction=function(t){t=Utils.createLambda(t);var n=this;return new Enumerable(function(){var e;return new IEnumerator(function(){e=n.getEnumerator()},function(){return!!e.moveNext()&&this.yieldReturn(e.current())},function(){try{Utils.dispose(e)}finally{t()}})})},Enumerable.prototype.log=function(t){return t=Utils.createLambda(t),this.doAction(function(e){typeof console!==Types.Undefined&&console.log(t(e))})},Enumerable.prototype.trace=function(t,n){return null==t&&(t="Trace"),n=Utils.createLambda(n),this.doAction(function(e){typeof console!==Types.Undefined&&console.log(t,n(e))})};var OrderedEnumerable=function(e,t,n,r,u){this.source=e,this.keySelector=Utils.createLambda(t),this.descending=r,this.parent=u,n&&(this.comparer=Utils.createLambda(n))};OrderedEnumerable.prototype=new Enumerable,OrderedEnumerable.prototype.createOrderedEnumerable=function(e,t,n){return new OrderedEnumerable(this.source,e,t,n,this)},OrderedEnumerable.prototype.thenBy=function(e,t){return this.createOrderedEnumerable(e,t,!1)},OrderedEnumerable.prototype.thenByDescending=function(e,t){return this.createOrderedEnumerable(e,t,!0)},OrderedEnumerable.prototype.getEnumerator=function(){var r,u,e=this,t=0;return new IEnumerator(function(){r=[],u=[],e.source.forEach(function(e,t){r.push(e),u.push(t)});var n=SortContext.create(e,null);n.GenerateKeys(r),u.sort(function(e,t){return n.compare(e,t)})},function(){return t<u.length&&this.yieldReturn(r[u[t++]])},Functions.Blank)};var SortContext=function(e,t,n,r){this.keySelector=e,this.descending=n,this.child=r,this.comparer=t,this.keys=null};SortContext.create=function(e,t){t=new SortContext(e.keySelector,e.comparer,e.descending,t);return null!=e.parent?SortContext.create(e.parent,t):t},SortContext.prototype.GenerateKeys=function(t){var n=t.length,r=this.keySelector,u=new Array(n);for(let e=0;e<n;e++)u[e]=r(t[e]);this.keys=u,null!=this.child&&this.child.GenerateKeys(t)},SortContext.prototype.compare=function(e,t){var n=this.comparer?this.comparer(this.keys[e],this.keys[t]):Utils.compare(this.keys[e],this.keys[t]);return 0==n?(null!=this.child?this.child:Utils).compare(e,t):this.descending?-n:n};var DisposableEnumerable=function(e,t){this.dispose=t,Enumerable.call(this,e)};DisposableEnumerable.prototype=new Enumerable;var ArrayEnumerable=function(e){this.getSource=function(){return e}};ArrayEnumerable.prototype=new Enumerable,ArrayEnumerable.prototype.any=function(e){return null==e?0<this.getSource().length:Enumerable.prototype.any.apply(this,arguments)},ArrayEnumerable.prototype.count=function(e){return null==e?this.getSource().length:Enumerable.prototype.count.apply(this,arguments)},ArrayEnumerable.prototype.elementAt=function(e){var t=this.getSource();return 0<=e&&e<t.length?t[e]:Enumerable.prototype.elementAt.apply(this,arguments)},ArrayEnumerable.prototype.elementAtOrDefault=function(e,t){void 0===t&&(t=null);var n=this.getSource();return 0<=e&&e<n.length?n[e]:t},ArrayEnumerable.prototype.first=function(e){var t=this.getSource();return null==e&&0<t.length?t[0]:Enumerable.prototype.first.apply(this,arguments)},ArrayEnumerable.prototype.firstOrDefault=function(e,t){if(void 0!==e)return Enumerable.prototype.firstOrDefault.apply(this,arguments);t=e;var n=this.getSource();return 0<n.length?n[0]:t},ArrayEnumerable.prototype.last=function(e){var t=this.getSource();return null==e&&0<t.length?t[t.length-1]:Enumerable.prototype.last.apply(this,arguments)},ArrayEnumerable.prototype.lastOrDefault=function(e,t){if(void 0!==e)return Enumerable.prototype.lastOrDefault.apply(this,arguments);t=e;var n=this.getSource();return 0<n.length?n[n.length-1]:t},ArrayEnumerable.prototype.skip=function(t){var n=this.getSource();return new Enumerable(function(){var e;return new IEnumerator(function(){e=t<0?0:t},function(){return e<n.length&&this.yieldReturn(n[e++])},Functions.Blank)})},ArrayEnumerable.prototype.takeExceptLast=function(e){return null==e&&(e=1),this.take(this.getSource().length-e)},ArrayEnumerable.prototype.takeFromLast=function(e){return this.skip(this.getSource().length-e)},ArrayEnumerable.prototype.reverse=function(){var t=this.getSource();return new Enumerable(function(){var e;return new IEnumerator(function(){e=t.length},function(){return 0<e&&this.yieldReturn(t[--e])},Functions.Blank)})},ArrayEnumerable.prototype.sequenceEqual=function(e,t){return(!(e instanceof ArrayEnumerable||e instanceof Array)||null!=t||Enumerable.from(e).count()==this.count())&&Enumerable.prototype.sequenceEqual.apply(this,arguments)},ArrayEnumerable.prototype.toJoinedString=function(e,t){var n=this.getSource();return null==t&&n instanceof Array?n.join(e=null==e?"":e):Enumerable.prototype.toJoinedString.apply(this,arguments)},ArrayEnumerable.prototype.getEnumerator=function(){var e=this.getSource(),t=-1;return{current:function(){return e[t]},moveNext:function(){return++t<e.length},dispose:Functions.Blank}};var WhereEnumerable=function(e,t){this.prevSource=e,this.prevPredicate=t};WhereEnumerable.prototype=new Enumerable,WhereEnumerable.prototype.where=function(t){if((t=Utils.createLambda(t)).length<=1){const n=this.prevPredicate;return new WhereEnumerable(this.prevSource,function(e){return n(e)&&t(e)})}return Enumerable.prototype.where.call(this,t)},WhereEnumerable.prototype.select=function(e){return(e=Utils.createLambda(e)).length<=1?new WhereSelectEnumerable(this.prevSource,this.prevPredicate,e):Enumerable.prototype.select.call(this,e)},WhereEnumerable.prototype.getEnumerator=function(){var e,t=this.prevPredicate,n=this.prevSource;return new IEnumerator(function(){e=n.getEnumerator()},function(){for(;e.moveNext();)if(t(e.current()))return this.yieldReturn(e.current());return!1},function(){Utils.dispose(e)})};var WhereSelectEnumerable=function(e,t,n){this.prevSource=e,this.prevPredicate=t,this.prevSelector=n};WhereSelectEnumerable.prototype=new Enumerable,WhereSelectEnumerable.prototype.where=function(e){return(e=Utils.createLambda(e)).length<=1?new WhereEnumerable(this,e):Enumerable.prototype.where.call(this,e)},WhereSelectEnumerable.prototype.select=function(t){if((t=Utils.createLambda(t)).length<=1){const n=this.prevSelector;return new WhereSelectEnumerable(this.prevSource,this.prevPredicate,function(e){return t(n(e))})}return Enumerable.prototype.select.call(this,t)},WhereSelectEnumerable.prototype.getEnumerator=function(){var e,t=this.prevPredicate,n=this.prevSelector,r=this.prevSource;return new IEnumerator(function(){e=r.getEnumerator()},function(){for(;e.moveNext();)if(null==t||t(e.current()))return this.yieldReturn(n(e.current()));return!1},function(){Utils.dispose(e)})};var Dictionary=function(){function i(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function a(e){return null===e?"null":void 0===e?"undefined":typeof e.toString===Types.Function?e.toString():Object.prototype.toString.call(e)}function l(e,t){this.key=e,this.value=t,this.prev=null,this.next=null}function t(){this.first=null,this.last=null}t.prototype={addLast:function(e){null!=this.last?((this.last.next=e).prev=this.last,this.last=e):this.first=this.last=e},replace:function(e,t){null!=e.prev?(e.prev.next=t).prev=e.prev:this.first=t,null!=e.next?(e.next.prev=t).next=e.next:this.last=t},remove:function(e){null!=e.prev?e.prev.next=e.next:this.first=e.next,null!=e.next?e.next.prev=e.prev:this.last=e.prev}};function e(e){this.countField=0,this.entryList=new t,this.buckets={},this.compareSelector=null==e?Functions.Identity:e}return e.prototype={add:function(e,t){var n=this.compareSelector(e),r=a(n),u=new l(e,t);if(i(this.buckets,r)){const o=this.buckets[r];for(let e=0;e<o.length;e++)if(this.compareSelector(o[e].key)===n)return this.entryList.replace(o[e],u),void(o[e]=u);o.push(u)}else this.buckets[r]=[u];this.countField++,this.entryList.addLast(u)},get:function(e){var t=this.compareSelector(e),e=a(t);if(i(this.buckets,e)){var n=this.buckets[e];for(let e=0;e<n.length;e++){var r=n[e];if(this.compareSelector(r.key)===t)return r.value}}},set:function(t,n){var r=this.compareSelector(t),e=a(r);if(i(this.buckets,e)){const o=this.buckets[e];for(let e=0;e<o.length;e++)if(this.compareSelector(o[e].key)===r){var u=new l(t,n);return this.entryList.replace(o[e],u),o[e]=u,!0}}return!1},contains:function(e){var t=this.compareSelector(e),e=a(t);if(!i(this.buckets,e))return!1;var n=this.buckets[e];for(let e=0;e<n.length;e++)if(this.compareSelector(n[e].key)===t)return!0;return!1},clear:function(){this.countField=0,this.buckets={},this.entryList=new t},remove:function(e){var t=this.compareSelector(e),n=a(t);if(i(this.buckets,n)){var r=this.buckets[n];for(let e=0;e<r.length;e++)if(this.compareSelector(r[e].key)===t)return this.entryList.remove(r[e]),r.splice(e,1),0==r.length&&delete this.buckets[n],void this.countField--}},count:function(){return this.countField},toEnumerable:function(){var e=this;return new Enumerable(function(){var t;return new IEnumerator(function(){t=e.entryList.first},function(){if(null==t)return!1;var e={key:t.key,value:t.value};return t=t.next,this.yieldReturn(e)},Functions.Blank)})}},e}(),Lookup=function(t){this.count=function(){return t.count()},this.get=function(e){return Enumerable.from(t.get(e))},this.contains=function(e){return t.contains(e)},this.toEnumerable=function(){return t.toEnumerable().select(function(e){return new Grouping(e.key,e.value)})}},Grouping=function(e,t){this.key=function(){return e},ArrayEnumerable.call(this,t)};Grouping.prototype=new ArrayEnumerable;export default Enumerable;