list-comprehension-in-js
Version:
List Comprehension in JavaScript
12 lines • 13.7 kB
JavaScript
/*!
*
* list-comprehension-in-js v0.0.17
* https://github.com/jfet97/list-comprehension-in-js
*
* Copyright (c) Andrea Simone Costa (https://github.com/jfet97)
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["list-comprehension-in-js"]=e():t["list-comprehension-in-js"]=e()}(this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=13)}([function(t,e,r){t.exports=r(4)},function(t,e,r){"use strict";r.r(e),r.d(e,"range",(function(){return s})),r.d(e,"rangeReversed",(function(){return f}));var n=r(0),o=r.n(n),a=o.a.mark(c),i=o.a.mark(s),u=o.a.mark(f);function c(){var t,e,r,n,i,u=arguments;return o.a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(t=0<u.length&&void 0!==u[0]?u[0]:0,e=1<u.length&&void 0!==u[1]?u[1]:0,r=2<u.length&&void 0!==u[2]?u[2]:function(t){return t},!(t<e)){o.next=13;break}n=t;case 5:if(!(n<=e)){o.next=11;break}return o.next=8,r&&r(n)||n;case 8:n++,o.next=5;break;case 11:o.next=20;break;case 13:i=t;case 14:if(!(i>=e)){o.next=20;break}return o.next=17,r&&r(i)||i;case 17:i--,o.next=14;break;case 20:case"end":return o.stop()}}),a)}function s(t,e){var r,n=arguments;return o.a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(r=2<n.length&&void 0!==n[2]?n[2]:function(t){return t},"number"==typeof t&&"number"==typeof e){o.next=3;break}throw TypeError("The 'start' and the 'end' actual parameters must be numbers");case 3:if(!(t<=e)){o.next=5;break}return o.delegateYield(c(t,e,r),"t0",5);case 5:case"end":return o.stop()}}),i)}function f(t,e){var r,n=arguments;return o.a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(r=2<n.length&&void 0!==n[2]?n[2]:function(t){return t},"number"==typeof t&&"number"==typeof e){o.next=3;break}throw TypeError("The 'start' and the 'end' actual parameters must be numbers");case 3:if(!(t>=e)){o.next=5;break}return o.delegateYield(c(t,e,r),"t0",5);case 5:case"end":return o.stop()}}),u)}},function(t,e,r){var n=r(9),o=r(5),a=r(10);t.exports=function(t){return n(t)||o(t)||a()}},function(t,e,r){"use strict";function n(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:0,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0;if("number"!=typeof r||"number"!=typeof e)throw TypeError("The 'start' and the 'nOfElements' actual parameters must be numbers");var n=[];if(0<=r&&0<e){var o=0,a=!0,i=!1,u=void 0;try{for(var c,s,f=t[Symbol.iterator]();!(a=(c=f.next()).done)&&(s=c.value,o!=r+e);a=!0)o>=r&&n.push(s),o++}catch(t){i=!0,u=t}finally{try{a||null==f.return||f.return()}finally{if(i)throw u}}}return n}r.r(e),r.d(e,"take",(function(){return n}))},function(t,e,r){var n=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r,n){var o=e&&e.prototype instanceof d?e:d,a=Object.create(o.prototype),i=new O(n||[]);return a._invoke=function(t,e,r){var n=f;return function(o,a){if(n===h)throw new Error("Generator is already running");if(n===p){if("throw"===o)throw a;return S()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=_(i,r);if(u){if(u===v)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===f)throw n=p,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=h;var c=s(t,e,r);if("normal"===c.type){if(n=r.done?p:l,c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=p,r.method="throw",r.arg=c.arg)}}}(t,r,i),a}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var f="suspendedStart",l="suspendedYield",h="executing",p="completed",v={};function d(){}function y(){}function m(){}var g={};g[a]=function(){return this};var b=Object.getPrototypeOf,x=b&&b(b(T([])));x&&x!==r&&n.call(x,a)&&(g=x);var w=m.prototype=d.prototype=Object.create(g);function k(t){["next","throw","return"].forEach((function(e){t[e]=function(t){return this._invoke(e,t)}}))}function E(t){var e;this._invoke=function(r,o){function a(){return new Promise((function(e,a){!function e(r,o,a,i){var u=s(t[r],t,o);if("throw"!==u.type){var c=u.arg,f=c.value;return f&&"object"==typeof f&&n.call(f,"__await")?Promise.resolve(f.__await).then((function(t){e("next",t,a,i)}),(function(t){e("throw",t,a,i)})):Promise.resolve(f).then((function(t){c.value=t,a(c)}),(function(t){return e("throw",t,a,i)}))}i(u.arg)}(r,o,e,a)}))}return e=e?e.then(a,a):a()}}function _(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,_(t,r),"throw"===r.method))return v;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=s(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function L(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function T(t){if(t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}return{next:S}}function S(){return{value:e,done:!0}}return y.prototype=w.constructor=m,m.constructor=y,m[u]=y.displayName="GeneratorFunction",t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,u in t||(t[u]="GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},k(E.prototype),E.prototype[i]=function(){return this},t.AsyncIterator=E,t.async=function(e,r,n,o){var a=new E(c(e,r,n,o));return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},k(w),w[u]="Generator",w[a]=function(){return this},w.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=T,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(j),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],u=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(c&&s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,v):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;j(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:T(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=n}catch(t){Function("r","regeneratorRuntime = r")(n)}},function(t,e){t.exports=function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}},function(t,e,r){var n=r(11),o=r(5),a=r(12);t.exports=function(t){return n(t)||o(t)||a()}},function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}},function(t,e){t.exports=function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(t,e){t.exports=function(t){if(Array.isArray(t))return t}},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(t,e,r){"use strict";r.r(e);var n=r(2),o=r.n(n),a=r(6),i=r.n(a),u=r(0),c=r.n(u),s=r(7),f=r.n(s),l=r(8),h=r.n(l);function p(t){return!("function"!=typeof t)}var v=function(){function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:function(){},r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:[];if(f()(this,t),!p(e))throw TypeError("The 'output' actual parameter must be a function");if(!r.every(p)||!n.every(p))throw TypeError("The 'ranges' and the 'predicates' actual parameters must be functions arrays");this._output=e,this._ranges=r,this._predicates=n}return h()(t,[{key:Symbol.iterator,value:c.a.mark((function t(){return c.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this._actualEval(this._ranges,[]),"t0",1);case 1:case"end":return t.stop()}}),t,this)}))},{key:"_actualEval",value:c.a.mark((function t(e,r){var n,a,u,s,f,l,h,p,v,d,y,m,g,b,x,w,k=this;return c.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=i()(e),a=n[0],u=n.slice(1),s=a.apply(void 0,o()(r)),0==u.length){t.next=30;break}f=!0,l=!1,h=void 0,t.prev=6,p=s[Symbol.iterator]();case 8:if(f=(v=p.next()).done){t.next=14;break}return d=v.value,t.delegateYield(this._actualEval(u,[].concat(o()(r),[d])),"t0",11);case 11:f=!0,t.next=8;break;case 14:t.next=20;break;case 16:t.prev=16,t.t1=t.catch(6),l=!0,h=t.t1;case 20:t.prev=20,t.prev=21,f||null==p.return||p.return();case 23:if(t.prev=23,!l){t.next=26;break}throw h;case 26:return t.finish(23);case 27:return t.finish(20);case 28:t.next=55;break;case 30:y=!0,m=!1,g=void 0,t.prev=33,b=c.a.mark((function(){var t;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=w.value,!k._predicates.every((function(e){return e.apply(void 0,[].concat(o()(r),[t]))}))){e.next=4;break}return e.next=4,k._output.apply(k,[].concat(o()(r),[t]));case 4:case"end":return e.stop()}}),b)})),x=s[Symbol.iterator]();case 36:if(y=(w=x.next()).done){t.next=41;break}return t.delegateYield(b(),"t2",38);case 38:y=!0,t.next=36;break;case 41:t.next=47;break;case 43:t.prev=43,t.t3=t.catch(33),m=!0,g=t.t3;case 47:t.prev=47,t.prev=48,y||null==x.return||x.return();case 50:if(t.prev=50,!m){t.next=53;break}throw g;case 53:return t.finish(50);case 54:return t.finish(47);case 55:case"end":return t.stop()}}),t,this,[[6,16,20,28],[21,,23,27],[33,43,47,55],[48,,50,54]])}))}]),t}(),d=r(1),y=r(3);r.d(e,"Comprehension",(function(){return v})),r.d(e,"range",(function(){return d.range})),r.d(e,"rangeReversed",(function(){return d.rangeReversed})),r.d(e,"take",(function(){return y.take}))}])}));