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 line
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