plexus-csp
Version:
A Go-inspired async library based on ES6 generators
1 lines • 25.2 kB
JavaScript
!function(t,n){if("object"==typeof exports&&"object"==typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e=n();for(var r in e)("object"==typeof exports?exports:t)[r]=e[r]}}(this,function(){return function(t){function n(r){if(e[r])return e[r].exports;var o=e[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n,e){e(8),t.exports=e(11)},function(t,n,e){"use strict";e(9);var r=e(3).impl.RingBuffer,o=e(2),i=function(){var t=r(64,65536),n=!0,e=function(){n=!0;for(var e=t.count();e>0;--e)t.read()()};return function(r){t.write(r),n&&(setImmediate(e),n=!1)}},u=i(),s=t.exports={};s.longStackSupport=!1,s.go=function(t){var n=Array.prototype.slice.call(arguments,1),e=t.apply(void 0,n),r=o(),i=function(t){u(function(){f(t,!0)})},c=function(t){u(function(){f(t,!1)})},a=s.longStackSupport?new Error:null,f=function(t,n){try{var o=n?e.next(t):e.throw(t),u=o.value;o.done?r.resolve(u):null!=u&&"function"==typeof u.then?u.then(i,c):i(u)}catch(t){return a&&"string"==typeof t.stack&&(t.stack=t.stack.replace(/\s*at GeneratorFunctionPrototype.next .*(\n.*)*/,"")+a.stack.replace(/.*/,"")),void r.reject(t)}};return i(),r}},function(t,n){"use strict";var e=0,r=1,o=2;t.exports=function(){function t(){l==r&&a?a(p):l==o&&f&&f(p)}function n(n,e){if(c())throw new Error("deferred is already resolved");l=n,p=e,t()}function i(n,e){null!=a||null!=f?e(new Error("deferred has already been subscribed to")):(a=n,f=e,t())}function u(t){n(r,t)}function s(t){n(o,t)}function c(){return l!=e}var a=null,f=null,l=e,p=void 0;return{then:i,resolve:u,reject:s,isResolved:c}}},function(t,n){"use strict";function e(t,n){function e(){return n}function r(){return l}function o(){return 0==l}function i(){return l==n}function u(e){l==t&&t<n&&c(Math.min(n,Math.max(1,Math.ceil(1.5*t))));var r=(f+l)%t;p[r]=e,l<t?l+=1:f=(f+1)%t}function s(){if(l>0){var n=p[f];return delete p[f],f=(f+1)%t,l=Math.max(l-1,0),n}}function c(n){var e=new Array(n);if(n<l)for(var r=f+l-n,o=0;o<n;++o)e[o]=p[(r+o)%t];else for(var o=0;o<l;++o)e[o]=p[(f+o)%t];t=n,f=0,l=Math.min(l,t),p=e}function a(e){e<t&&c(e),n=e}var t=t,n=n||t,f=0,l=0,p=new Array(t);return{capacity:e,count:r,isEmpty:o,isFull:i,write:u,read:s,resize:a}}function r(t){return function(n){function r(){return t==o}function i(n){if(c.isFull()&&t!=u){if(t==o)return!1}else c.write(n);return!0}function s(){return c.isEmpty()?[]:[c.read()]}var c=e(n||1);return{canFail:r,push:i,pull:s}}}var o=0,i=1,u=2;t.exports={Buffer:r(o),DroppingBuffer:r(i),SlidingBuffer:r(u),impl:{RingBuffer:e}}},function(t,n,e){"use strict";var r=e(2),o=e(3),i=e(6),u=8192,s=function(t,n,e){return!t.pending.isFull()&&(t.pending.write(n),void 0!==e&&t.data.write(e),!0)},c=function(t,n){return!!t.buffer&&t.buffer.push(n)},a=function(t){if(t.buffer)return t.buffer.pull()[0]},f=function(t,n){for(var e;t.pressure<0;)if(e=t.pending.read(),++t.pressure,!e.isResolved())return e.resolve(n),!0;return c(t,n)},l=function(t,n,e){e.isResolved()||(void 0===n?e.reject(new Error("push() requires a value")):t.isClosed?e.resolve(!1):f(t,n)?e.resolve(!0):s(t,e,n)?++t.pressure:e.reject(new Error("channel queue overflow")))},p=function(t){for(var n,e,r;t.pressure>0;)if(n=t.pending.read(),e=t.data.read(),--t.pressure,!n.isResolved())return r=a(t),void 0!==r&&(c(t,e),e=r),n.resolve(!0),e;return a(t)},h=function(t,n){if(!n.isResolved()){var e=p(t);void 0!==e?n.resolve(e):t.isClosed?n.resolve():s(t,n)?--t.pressure:n.reject(new Error("channel queue overflow"))}},d=function(t){for(var n,e=t.pressure<0&&void 0;t.pending&&!t.pending.isEmpty();)n=t.pending.read(),n.isResolved()||n.resolve(e);t.pending=null,t.data=null,t.pressure=0,t.isClosed=!0};n.chan=function(t,n){var e={buffer:t&&("object"==typeof t?t:o.Buffer(t)),pending:o.impl.RingBuffer(32,u),data:o.impl.RingBuffer(32,u),pressure:0,isClosed:!1},s={push:function(t,n){var o=n||r();return l(e,t,o),o},pull:function(t){var n=t||r();return h(e,n),n},close:function(){d(e)}};return"function"==typeof n?i(s,n):s},n.push=function(t,n){return t.push(n)},n.pull=function(t){return t.pull()},n.close=function(t){t.close()};var v=function(t){return null!=t&&t.constructor===Object&&"function"!=typeof t.pull},x=function(t){var n,e,r;for(n=t.length;n>1;--n)e=Math.floor(Math.random()*n),r=t[e],t[e]=t[n-1],t[n-1]=r},y=function(t,n){return{resolve:function(e){n.resolve({channel:t,value:e})},reject:function(t){n.reject(t)},isResolved:function(){return n.isResolved()}}};n.select=function(){var t,n,e=Array.prototype.slice.call(arguments),o=v(e[e.length-1])?e.pop():{},i=r();for(o.priority||x(e),t=0;t<e.length;++t)n=e[t],null!=n&&(Array.isArray(n)?n[0].push(n[1],y(n[0],i)):n.pull(y(n,i)));return o.hasOwnProperty("default")&&!i.isResolved()&&i.resolve({channel:null,value:o.default}),i}},function(t,n,e){"use strict";var r=e(1),o=e(4);n.timeout=function(t){var n=o.chan(),e=setTimeout(function(){clearTimeout(e),o.close(n)},t);return n},n.ticker=function(t){var n,e=o.chan(),i=function(){clearTimeout(n),n=setTimeout(i,t),r.go(wrapGenerator.mark(function(){return wrapGenerator(function(t){for(;;)switch(t.next){case 0:return t.next=2,o.push(e,null);case 2:if(t.sent){t.next=4;break}clearTimeout(n);case 4:case"end":return t.stop()}},this)}))};return n=setTimeout(i,t),e},n.each=function(t,n){return r.go(wrapGenerator.mark(function(){var e;return wrapGenerator(function(r){for(;;)switch(r.next){case 0:return r.next=2,o.pull(n);case 2:if(r.t2=e=r.sent,void 0===r.t2){r.next=9;break}if(!t){r.next=7;break}return r.next=7,t(e);case 7:r.next=0;break;case 9:case"end":return r.stop()}},this)}))},n.pipe=function(t,n,e){return r.go(wrapGenerator.mark(function(){var r;return wrapGenerator(function(o){for(;;)switch(o.next){case 0:return o.next=2,t.pull();case 2:if(o.t3=r=o.sent,void 0===o.t3){o.next=12;break}return o.next=6,n.push(r);case 6:if(o.sent){o.next=10;break}delete o.thrown,o.next=12;break;case 10:o.next=0;break;case 12:e||(t.close(),n.close());case 13:case"end":return o.stop()}},this)}))},n.createLock=function(){var t=o.chan();return t.push(null),{acquire:function(){return t.pull()},release:function(){return t.push(null)}}},n.iterate=function(t){var n=!1;return{pull:function(e){var o,i=e||r.defer();return n||(o=t(),void 0===o&&(n=!0)),i.resolve(o),i},close:function(){n=!0}}},n.generate=function(t){var e=t();return n.iterate(function(){var t=e.next();return t.done?void 0:t.value})},n.fromStream=function(t,e){var i=o.chan(),u=n.createLock();return t.on("readable",function(){r.go(wrapGenerator.mark(function(){var n;return wrapGenerator(function(r){for(;;)switch(r.next){case 0:return r.next=2,u.acquire();case 2:if(null===(n=t.read())){r.next=12;break}return r.next=5,i.push(n);case 5:if(r.sent){r.next=10;break}e&&e(),delete r.thrown,r.next=12;break;case 10:r.next=2;break;case 12:u.release();case 13:case"end":return r.stop()}},this)}))}),t.on("end",function(){r.go(wrapGenerator.mark(function(){return wrapGenerator(function(t){for(;;)switch(t.next){case 0:return t.next=2,u.acquire();case 2:i.close();case 3:case"end":return t.stop()}},this)}))}),t.on("error",function(t){throw new Error(t)}),i};var i=function(t,n){return t.then(function(t){n.resolve(t)},function(t){n.reject(t)}),n};n.multiChan=function(){var t=!0,e=n.createLock(),o=[];return{push:function(n,u){if(!t)return void u.resolve(!1);if(void 0===n)return void u.reject(new Error("push() requires a value"));var s=r.go(wrapGenerator.mark(function(){var t;return wrapGenerator(function(r){for(;;)switch(r.next){case 0:return r.next=2,e.acquire();case 2:t=0;case 3:if(!(t<o.length)){r.next=9;break}return r.next=6,o[t].push(n);case 6:++t,r.next=3;break;case 9:e.release(),r.rval=!0,delete r.thrown,r.next=14;break;case 14:case"end":return r.stop()}},this)}));return u?i(s,u):s},close:function(){t=!1},tap:function(t){return r.go(wrapGenerator.mark(function(){return wrapGenerator(function(n){for(;;)switch(n.next){case 0:return n.next=2,e.acquire();case 2:o.push(t),e.release();case 4:case"end":return n.stop()}},this)}))},untap:function(t){return r.go(wrapGenerator.mark(function(){var n;return wrapGenerator(function(r){for(;;)switch(r.next){case 0:return r.next=2,e.acquire();case 2:n=o.indexOf(t),n>=0&&o.splice(n,1),e.release();case 5:case"end":return r.stop()}},this)}))},untapAll:function(){return r.go(wrapGenerator.mark(function(){return wrapGenerator(function(t){for(;;)switch(t.next){case 0:return t.next=2,e.acquire();case 2:o.splice(0),e.release();case 4:case"end":return t.stop()}},this)}))}}}},function(t,n,e){"use strict";var r=e(1),o=function(t){return t&&t.__transducers_reduced__},i=function(t){return o(t)?t.value:t},u=function(t,n){return t.then(function(t){n.resolve(t)},function(t){n.reject(t)}),n},s=function(t){return{init:function(){return!0},result:function(t){return t},step:function(n,e){return r.go(wrapGenerator.mark(function(){return wrapGenerator(function(r){for(;;)switch(r.next){case 0:return r.next=2,n;case 2:return n=r.sent,r.next=5,e;case 5:if(e=r.sent,void 0===e){r.next=13;break}return r.next=9,t.push(e);case 9:r.rval=r.sent,delete r.thrown,r.next=13;break;case 13:case"end":return r.stop()}},this)}))}}};t.exports=function(t,n){var e=!0,c=n(s(t)),a=c.init();return{push:function(n,s){var f=r.go(wrapGenerator.mark(function(){var r;return wrapGenerator(function(u){for(;;)switch(u.next){case 0:if(r=e,!e){u.next=14;break}return u.next=4,c.step(a,n);case 4:if(a=u.sent,!o(a)){u.next=13;break}return e=!1,u.next=9,i(a);case 9:return u.t4=u.sent,u.next=12,c.result(u.t4);case 12:t.close();case 13:case 14:u.rval=r,delete u.thrown,u.next=18;break;case 18:case"end":return u.stop()}},this)}));return s?u(f,s):f},pull:function(n){return t.pull(n)},close:function(){e&&(e=!1,r.top(r.go(wrapGenerator.mark(function(){return wrapGenerator(function(n){for(;;)switch(n.next){case 0:return n.next=2,c.result(a);case 2:t.close();case 3:case"end":return n.stop()}},this)}))))}}}},function(t,n,e){"use strict";var r=e(2),o=e(1),i=function(t){t.then(null,function(t){console.log(t.stack)})},u=function(t){return o.go(wrapGenerator.mark(function(){var n,e;return wrapGenerator(function(r){for(;;)switch(r.next){case 0:n=[],e=0;case 2:if(!(e<t.length)){r.next=10;break}return r.next=5,t[e];case 5:r.t0=r.sent,n.push(r.t0);case 7:++e,r.next=2;break;case 10:r.rval=n,delete r.thrown,r.next=14;break;case 14:case"end":return r.stop()}},this)}))},s=function(t,n){return function(){var e=Array.prototype.slice.call(arguments);return o.go(wrapGenerator.mark(function(){return wrapGenerator(function(r){for(;;)switch(r.next){case 0:return r.next=2,u(e);case 2:r.t1=r.sent,r.rval=t.apply(n,r.t1),delete r.thrown,r.next=7;break;case 7:case"end":return r.stop()}},this)}))}},c=function(t){var n=Array.prototype.slice.call(arguments,1);return o.go(wrapGenerator.mark(function(){var e,r,o;return wrapGenerator(function(i){for(;;)switch(i.next){case 0:e=t,o=0;case 2:if(!(o<n.length)){i.next=11;break}return r=n[o],i.next=6,e;case 6:e=i.sent,e="function"==typeof r?r(e):Array.isArray(r)&&"function"==typeof r[0]?r[0].apply(null,[].concat(r[1],[e],r.slice(2))):Array.isArray(r)&&"string"==typeof r[0]?e[r[0]].apply(e,r.slice(1)):r;case 8:++o,i.next=2;break;case 11:return i.next=13,e;case 13:i.rval=i.sent,delete i.thrown,i.next=17;break;case 17:case"end":return i.stop()}},this)}))},a=function(t){var n=r(),e=setTimeout(function(){clearTimeout(e),n.resolve()},t);return n},f=function(t){return function(n,e){n?t.reject(new Error(n)):t.resolve(e)}},l=function(t,n){var e=Array.prototype.slice.call(arguments,2);return function(){var o=Array.prototype.slice.call(arguments),i=r();return t.apply(n,e.concat(o,f(i))),i}},p=function(t,n){return void 0===n?t:void t.then(function(t){n(null,t)},function(t){n(t)})};t.exports={top:i,join:u,lift:s,chain:c,sleep:a,ncallback:f,nbind:l,nodeify:p}},function(t,n,e){(function(t,e){function r(t,n){return new o(t,n||null)}function o(t,n){function e(e,r){if(u===a)throw new Error("Generator is already running");if(u===f)throw new Error("Generator has already finished");for(;;){var i=o.delegate;if(i){try{var p=i.generator[e](r);e="next",r=void 0}catch(t){o.delegate=null,e="throw",r=t;continue}if(!p.done)return u=c,p;o[i.resultName]=p.value,o.next=i.nextLoc,o.delegate=null}if("next"===e){if(u===s&&"undefined"!=typeof r)throw new TypeError("attempt to send "+JSON.stringify(r)+" to newborn generator");u===c?o.sent=r:delete o.sent}else if("throw"===e){if(u===s)throw u=f,r;o.dispatchException(r)&&(e="next",r=void 0)}u=a;try{var h=t.call(n,o);u=o.done?f:c;var p={value:h,done:o.done};if(h!==l)return p;o.delegate&&"next"===e&&(r=void 0)}catch(t){"next"===e?o.dispatchException(t):r=t}}}var r=this,o=new i,u=s;r.next=e.bind(r,"next"),r.throw=e.bind(r,"throw")}function i(){this.reset()}var u=Object.prototype.hasOwnProperty;if(!t.wrapGenerator){t.wrapGenerator=r,n.wrapGenerator=r;var s="suspendedStart",c="suspendedYield",a="executing",f="completed",l={};r.mark=function(t){return t.constructor=e,t},"GeneratorFunction"!==e.name&&(e.name="GeneratorFunction"),r.isGeneratorFunction=function(t){var n=t&&t.constructor;return!!n&&e.name===n.name},o.prototype.toString=function(){return"[object Generator]"},i.prototype={constructor:i,reset:function(){this.next=0,this.sent=void 0,this.tryStack=[],this.done=!1,this.delegate=null;for(var t,n=0;u.call(this,t="t"+n)||n<20;++n)this[t]=null},stop:function(){if(this.done=!0,u.call(this,"thrown")){var t=this.thrown;throw delete this.thrown,t}return this.rval},keys:function(t){return Object.keys(t).reverse()},pushTry:function(t,n,e){n&&this.tryStack.push({finallyLoc:n,finallyTempVar:e}),t&&this.tryStack.push({catchLoc:t})},popCatch:function(t){var n=this.tryStack.length-1,e=this.tryStack[n];e&&e.catchLoc===t&&(this.tryStack.length=n)},popFinally:function(t){var n=this.tryStack.length-1,e=this.tryStack[n];e&&u.call(e,"finallyLoc")||(e=this.tryStack[--n]),e&&e.finallyLoc===t&&(this.tryStack.length=n)},dispatchException:function(t){var n=[],e=!1;if(this.done)throw t;this.thrown=t,this.next="end";for(var r=this.tryStack.length-1;r>=0;--r){var o=this.tryStack[r];if(o.catchLoc){this.next=o.catchLoc,e=!0;break}o.finallyLoc&&n.push(o)}for(;o=n.pop();)this[o.finallyTempVar]=this.next,this.next=o.finallyLoc;return e},delegateYield:function(t,n,e){return this.delegate={generator:t,resultName:n,nextLoc:e},l}}}}).apply(this,Function("return [this, function GeneratorFunction(){}]")())},function(t,n){!function(t,n){"use strict";function e(t){return d[h]=r.apply(n,t),h++}function r(t){var e=[].slice.call(arguments,1);return function(){"function"==typeof t?t.apply(n,e):new Function(""+t)()}}function o(t){if(v)setTimeout(r(o,t),0);else{var n=d[t];if(n){v=!0;try{n()}finally{i(t),v=!1}}}}function i(t){delete d[t]}function u(){p=function(){var t=e(arguments);return process.nextTick(r(o,t)),t}}function s(){if(t.postMessage&&!t.importScripts){var n=!0,e=t.onmessage;return t.onmessage=function(){n=!1},t.postMessage("","*"),t.onmessage=e,n}}function c(){var n="setImmediate$"+Math.random()+"$",r=function(e){e.source===t&&"string"==typeof e.data&&0===e.data.indexOf(n)&&o(+e.data.slice(n.length))};t.addEventListener?t.addEventListener("message",r,!1):t.attachEvent("onmessage",r),p=function(){var r=e(arguments);return t.postMessage(n+r,"*"),r}}function a(){var t=new MessageChannel;t.port1.onmessage=function(t){var n=t.data;o(n)},p=function(){var n=e(arguments);return t.port2.postMessage(n),n}}function f(){var t=x.documentElement;p=function(){var n=e(arguments),r=x.createElement("script");return r.onreadystatechange=function(){o(n),r.onreadystatechange=null,t.removeChild(r),r=null},t.appendChild(r),n}}function l(){p=function(){var t=e(arguments);return setTimeout(r(o,t),0),t}}if(!t.setImmediate){var p,h=1,d={},v=!1,x=t.document,y=Object.getPrototypeOf&&Object.getPrototypeOf(t);y=y&&y.setTimeout?y:t,"[object process]"==={}.toString.call(t.process)?u():s()?c():t.MessageChannel?a():x&&"onreadystatechange"in x.createElement("script")?f():l(),y.setImmediate=p,y.clearImmediate=i}}(new Function("return this")())},function(t,n){function e(t,n){throw new Error("don't know how to "+t+" collection: "+n)}function r(t,n){return"iterator"===n?t[rt.iterator]||t.next:t[rt[n]]}function o(t,n){return t[rt[n]]}function i(t){var n=o(t,"iterator");return n?n.call(t):t.next?t:it(t)?new u(t):a(t)?new s(t):void 0}function u(t){this.arr=t,this.index=0}function s(t){this.obj=t,this.keys=Object.keys(t),this.index=0}function c(t){return"function"==typeof t}function a(t){return t instanceof Object&&Object.getPrototypeOf(t)===Object.getPrototypeOf({})}function f(t){return"number"==typeof t}function l(t){this.__transducers_reduced__=!0,this.value=t}function p(t){return t instanceof l||t&&t.__transducers_reduced__}function h(t){return t.value}function d(t){return p(t)?t:new l(t)}function v(t){return p(t)?h(t):t}function x(t,n,o){if(it(t)){for(var u=o,s=-1,c=t.length;++s<c;)if(u=n.step(u,t[s]),p(u)){u=h(u);break}return n.result(u)}if(a(t)||r(t,"iterator")){for(var u=o,f=i(t),l=f.next();!l.done;){if(u=n.step(u,l.value),p(u)){u=h(u);break}l=f.next()}return n.result(u)}e("iterate",t)}function y(t,n,e,r){return n=n(e),void 0===r&&(r=n.init()),x(t,n,r)}function m(){var t=Array.prototype.slice.call(arguments);return function(n){for(var e=n,r=t.length-1;r>=0;r--)e=t[r](e);return e}}function w(t){return{init:function(){throw new Error("init value unavailable")},result:function(t){return t},step:t}}function g(t,n,e){if(e=null!=e?e:1,!n)return t;switch(e){case 1:return function(e){return t.call(n,e)};case 2:return function(e,r){return t.call(n,e,r)};default:return t.bind(n)}}function k(t,n,e){var r=-1,o=t.length,i=Array(o);for(n=g(n,e,2);++r<o;)i[r]=n(t[r],r);return i}function b(t,n,e){var r=t.length,o=[];n=g(n,e,2);for(var i=0;i<r;i++)n(t[i],i)&&o.push(t[i]);return o}function G(t,n){this.xform=n,this.f=t}function j(t,n,e){return c(t)&&(e=n,n=t,t=null),n=g(n,e),t?it(t)?k(t,n,e):U(t,j(n)):function(t){return new G(n,t)}}function S(t,n){this.xform=n,this.f=t}function A(t,n,e){return c(t)&&(e=n,n=t,t=null),n=g(n,e),t?it(t)?b(t,n,e):U(t,A(n)):function(t){return new S(n,t)}}function E(t,n,e){return c(t)&&(e=n,n=t,t=null),n=g(n,e),A(t,function(t){return!n(t)})}function O(t){return A(t,function(t){return null!=t})}function _(t){this.xform=t,this.last=void 0}function L(t){return t?U(t,L()):function(t){return new _(t)}}function T(t,n){this.xform=n,this.f=t}function R(t,n,e){return c(t)&&(e=n,n=t,t=null),n=g(n,e),t?U(t,R(n)):function(t){return new T(n,t)}}function M(t,n){this.n=t,this.i=0,this.xform=n}function q(t,n){return f(t)&&(n=t,t=null),t?U(t,q(n)):function(t){return new M(n,t)}}function F(t,n){this.n=t,this.i=0,this.xform=n}function C(t,n){return f(t)&&(n=t,t=null),t?U(t,C(n)):function(t){return new F(n,t)}}function B(t,n){this.xform=n,this.f=t,this.dropping=!0}function P(t,n,e){return c(t)&&(e=n,n=t,t=null),n=g(n,e),t?U(t,P(n)):function(t){return new B(n,t)}}function I(t,n){this.n=t,this.i=0,this.xform=n,this.part=new Array(t)}function N(t,n){return f(t)&&(n=t,t=null),t?U(t,N(n)):function(t){return new I(n,t)}}function z(t,n){this.f=t,this.xform=n,this.part=[],this.last=ut}function V(t,n,e){return c(t)&&(e=n,n=t,t=null),n=g(n,e),t?U(t,V(n)):function(t){return new z(n,t)}}function W(t){this.xform=t}function Y(t){return new W(t)}function $(t,n){return t=g(t,n),m(j(t),Y)}function D(t,n){return t.push(n),t}function J(t,n){if(it(n)&&2===n.length)t[n[0]]=n[1];else for(var e=Object.keys(n),r=e.length,o=0;o<r;o++)t[e[o]]=n[e[o]];return t}function H(t,n){return n?y(t,n,st,[]):x(t,st,[])}function K(t,n){return n?y(t,n,ct,{}):x(t,ct,{})}function Q(t,n){return n?new tt(n,t):i(t)}function U(t,n){if(it(t))return y(t,n,st,[]);if(a(t))return y(t,n,ct,{});if(r(t,"transformer")){var i=o(t,"transformer");return y(t,n,i,i.init())}return r(t,"iterator")?new tt(n,t):void e("sequence",t)}function X(t,n,i){return it(t)?y(i,n,st,t):a(t)?y(i,n,ct,t):r(t,"transformer")?y(i,n,o(t,"transformer"),t):void e("into",t)}function Z(t,n){this.xform=t(at),this.iter=n}function tt(t,n){this.iter=i(n),this.items=[],this.stepper=new Z(t,i(n))}function nt(t){for(var n=new Array(t),e=0;e<n.length;e++)n[e]=e;return n}var et="undefined"!=typeof Symbol,rt={iterator:et?Symbol.iterator:"@@iterator",transformer:et?Symbol("transformer"):"@@transformer"};u.prototype.next=function(){return this.index<this.arr.length?{value:this.arr[this.index++],done:!1}:{done:!0}},s.prototype.next=function(){if(this.index<this.keys.length){var t=this.keys[this.index++];return{value:[t,this.obj[t]],done:!1}}return{done:!0}};var ot=Object.prototype.toString,it="function"==typeof Array.isArray?Array.isArray:function(t){return"[object Array]"==ot.call(t)};G.prototype.init=function(){return this.xform.init()},G.prototype.result=function(t){return this.xform.result(t)},G.prototype.step=function(t,n){return this.xform.step(t,this.f(n))},S.prototype.init=function(){return this.xform.init()},S.prototype.result=function(t){return this.xform.result(t)},S.prototype.step=function(t,n){return this.f(n)?this.xform.step(t,n):t},_.prototype.init=function(){return this.xform.init()},_.prototype.result=function(t){return this.xform.result(t)},_.prototype.step=function(t,n){return n!==this.last?(this.last=n,this.xform.step(t,n)):t},T.prototype.init=function(){return this.xform.init()},T.prototype.result=function(t){return this.xform.result(t)},T.prototype.step=function(t,n){return this.f(n)?this.xform.step(t,n):new l(t)},M.prototype.init=function(){return this.xform.init()},M.prototype.result=function(t){return this.xform.result(t)},M.prototype.step=function(t,n){return this.i<this.n&&(t=this.xform.step(t,n),this.i+1>=this.n&&(t=d(t))),this.i++,t},F.prototype.init=function(){return this.xform.init()},F.prototype.result=function(t){return this.xform.result(t)},F.prototype.step=function(t,n){return this.i++<this.n?t:this.xform.step(t,n)},B.prototype.init=function(){return this.xform.init()},B.prototype.result=function(t){return this.xform.result(t)},B.prototype.step=function(t,n){if(this.dropping){if(this.f(n))return t;this.dropping=!1}return this.xform.step(t,n)},I.prototype.init=function(){return this.xform.init()},I.prototype.result=function(t){return this.i>0?v(this.xform.step(t,this.part.slice(0,this.i))):this.xform.result(t)},I.prototype.step=function(t,n){if(this.part[this.i]=n,this.i+=1,this.i===this.n){var e=this.part.slice(0,this.n);return this.part=new Array(this.n),this.i=0,this.xform.step(t,e)}return t};var ut={};z.prototype.init=function(){return this.xform.init()},z.prototype.result=function(t){var n=this.part.length;return n>0?v(this.xform.step(t,this.part.slice(0,n))):this.xform.result(t)},z.prototype.step=function(t,n){var e=this.f(n);return e===this.last||this.last===ut?this.part.push(n):(t=this.xform.step(t,this.part),this.part=[n]),this.last=e,t},W.prototype.init=function(){return this.xform.init()},W.prototype.result=function(t){return this.xform.result(t)},W.prototype.step=function(t,n){var e=this.xform,r={init:function(){return e.init()},result:function(t){return t},step:function(t,n){var r=e.step(t,n);return p(r)?h(r):r}};return x(n,r,t)};var st={init:function(){return[]},result:function(t){return t},step:D},ct={init:function(){return{}},result:function(t){return t},step:J},at={result:function(t){return p(t)?h(t):t},step:function(t,n){return t.items.push(n),t.rest}};Z.prototype.step=function(t){for(var n=t.items.length;t.items.length===n;){var e=this.iter.next();if(e.done||p(e.value)){this.xform.result(this);break}this.xform.step(t,e.value)}},tt.prototype[rt.iterator]=function(){return this},tt.prototype.next=function(){return this.step(),this.items.length?{value:this.items.pop(),done:!1}:{done:!0}},tt.prototype.step=function(){this.items.length||this.stepper.step(this)},t.exports={reduce:x,transformer:w,Reduced:l,iterator:i,push:D,merge:J,transduce:y,seq:U,toArray:H,toObj:K,toIter:Q,into:X,compose:m,map:j,filter:A,remove:E,cat:Y,mapcat:$,keep:O,dedupe:L,take:q,takeWhile:R,drop:C,dropWhile:P,partition:N,partitionBy:V,range:nt,protocols:rt,LazyTransformer:tt}},function(t,n,e){"use strict";var r=function(t,n){for(var e in n)t[e]=n[e]},o=t.exports=e(1);o.defer=e(2),o.transducers=e(12),r(o,e(3)),r(o,e(1)),r(o,e(7)),r(o,e(4)),r(o,e(5))},function(t,n,e){"use strict";var r=e(10),o=function(t){return t&&t.__transducers_reduced__},i=function(t){return o(t)?t.value:t},u=function(t){return{init:function(){return t.init()},result:function(t){return t},step:function(n,e){var i=t.step(n,e);return o(i)?new r.Reduced(i):i}}},s=function(t){var n=u(t);return{init:function(){return t.init()},result:function(n){return t.result(n)},step:function(t,e){return r.reduce(e,n,t)}}},c=function(t){return r.compose(r.map(t),s)},a=function(t,n){return function(e){return{init:function(){return{acc:e.init(),val:n}},result:function(t){return e.result(t.acc)},step:function(n,r){var o=void 0===n.val?r:t(n.val,r);return{acc:e.step(n.acc,o),val:o}}}}},f=function(t){return function(n){var e=[];return{init:function(){return n.init()},result:function(r){e.sort(t);for(var u=0;u<e.length&&(r=n.step(r,e[u]),!o(r));++u);return i(n.result(r))},step:function(t,n){return e.push(n),t}}}};t.exports={cat:s,mapcat:c,reductions:a,sort:f}}])});