Comparing version 0.0.32 to 0.0.33
@@ -1,3 +0,3 @@ | ||
/*! spica v0.0.32 https://github.com/falsandtru/spica | (c) 2016, falsandtru | MIT License */ | ||
define="function"==typeof define&&define.amd?define:function(){"use strict";var e="spica",n={};return function t(r,i,u){return u?void u.apply(this,i.map(function(e){switch(e){case"require":return"function"==typeof require?require:void 0;case"exports":return r.indexOf("/")===-1?n[r]="undefined"==typeof exports?self[r]=self[r]||{}:exports:n[r]=n.hasOwnProperty(r)?n[r]:{};default:return".d"===e.slice(-2)&&{}||n.hasOwnProperty(e)&&n[e]||"function"==typeof require&&require(e)||self[e]}})):void t(e,r,i)}}();var __extends=this&&this.__extends||function(e,n){function t(){this.constructor=e}for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r]);e.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)};define("src/lib/concat",["require","exports"],function(e,n){"use strict";function t(e,n){for(var t=0,r=n.length,i=e.length;t<r;++t)e[t+i]=n[t];return e}n.concat=t}),define("src/lib/observable",["require","exports","src/lib/concat"],function(e,n,t){"use strict";var r=function(){function e(){this.node_={parent:void 0,childrenMap:Object.create(null),childrenList:[],registers:[]}}return e.prototype.monitor=function(e,n,t){var r=this;return void 0===t&&(t=n),void this.throwTypeErrorIfInvalidSubscriber_(n,e),void this.seekNode_(e).registers.push([e,t,!0,n]),function(){return r.off(e,t)}},e.prototype.on=function(e,n,t){var r=this;return void 0===t&&(t=n),void this.throwTypeErrorIfInvalidSubscriber_(n,e),void this.seekNode_(e).registers.push([e,t,!1,function(e){return n(e)}]),function(){return r.off(e,t)}},e.prototype.off=function(e,n){switch(typeof n){case"function":return void this.seekNode_(e).registers.some(function(e,t,r){var i=e[1];if(n!==i)return!1;switch(t){case 0:return!void r.shift();case r.length-1:return!void r.pop();default:return!void r.splice(t,1)}});case"undefined":var t=this.seekNode_(e);return t.childrenMap=Object.create(null),t.childrenList=[],void(t.registers=[]);default:throw this.throwTypeErrorIfInvalidSubscriber_(n,e)}},e.prototype.once=function(e,n){var t=this;return void this.throwTypeErrorIfInvalidSubscriber_(n,e),this.on(e,function(r){return void t.off(e,n),n(r)},n)},e.prototype.emit=function(e,n,t){void this.drain_(e,n,t)},e.prototype.reflect=function(e,n){var t=[];return void this.emit(e,n,function(e,n){return t=n}),t},e.prototype.drain_=function(e,n,t){var r=[];if(void this.refsBelow_(this.seekNode_(e)).reduce(function(e,i){var u=i[2],o=i[3];if(!u)try{var c=o(n);t&&(r[r.length]=c)}catch(e){void 0!==e&&null!==e&&void console.error(e+"")}},void 0),void this.refsAbove_(this.seekNode_(e)).reduce(function(e,t){var r=t[2],i=t[3];if(r)try{void i(n)}catch(e){void 0!==e&&null!==e&&void console.error(e)}},void 0),t)try{void t(n,r)}catch(e){void console.error(e)}},e.prototype.refs=function(e){return this.refsBelow_(this.seekNode_(e))},e.prototype.refsAbove_=function(e){var n=e.parent,r=e.registers;for(r=t.concat([],r);n;)r=t.concat(r,n.registers),n=n.parent;return r},e.prototype.refsBelow_=function(e){var n=e.childrenList,r=e.childrenMap,i=e.registers;i=t.concat([],i);for(var u=0;u<n.length;++u){var o=n[u],c=this.refsBelow_(r[o]);i=t.concat(i,c),0===c.length&&(void delete r[o],void n.splice(n.indexOf(o),1),void--u)}return i},e.prototype.seekNode_=function(e){for(var n=this.node_,t=0,r=e;t<r.length;t++){var i=r[t],u=n.childrenMap;u[i+""]||(void n.childrenList.push(i+""),u[i+""]={parent:n,childrenMap:Object.create(null),childrenList:[],registers:[]}),n=u[i+""]}return n},e.prototype.throwTypeErrorIfInvalidSubscriber_=function(e,n){switch(typeof e){case"function":return;default:throw new TypeError("Spica: Observable: Invalid subscriber.\n\t"+e)}},e}();n.Observable=r}),define("src/lib/sqid",["require","exports"],function(e,n){"use strict";function t(e){if(arguments.length>0){if("number"!=typeof e)throw new TypeError("Spica: sqid: A parameter value must be a number: "+e);if(e>=0==!1)throw new TypeError("Spica: sqid: A parameter value must be a positive number: "+e);if(e%1!==0)throw new TypeError("Spica: sqid: A parameter value must be an integer: "+e)}return void 0===e?(1e15+ ++r+"").slice(1):(1e15+e+"").slice(1)}var r=0;n.sqid=t}),define("src/lib/type",["require","exports"],function(e,n){"use strict";function t(e){return Object.prototype.toString.call(e).split(" ").pop().slice(0,-1)}n.type=t}),define("src/lib/collection/datamap",["require","exports","src/lib/sqid","src/lib/type"],function(e,n,t,r){"use strict";function i(e){return e instanceof Object==!1}var u=function(){function e(e){var n=this;void 0===e&&(e=[]),this.store=new Map,this.weakstore=new WeakMap,void Array.from(e).forEach(function(e){var t=e[0],r=e[1];return void n.set(t,r)})}return e.prototype.stringify=function(e){switch(typeof e){case"undefined":return"0:"+e;case"boolean":return"1:"+e;case"number":return"2:"+(1e3+(""+e).length)+":"+e;case"string":return"3:"+(1e14+e.length)+":"+e;default:return i(e)?"8:"+e:Array.isArray(e)?"9:[ "+this.stringifyArray(e)+" ]":"9:{ "+(this.stringifyObject(e)||this.weakstore.get(e)||this.weakstore.set(e,t.sqid()).get(e))+" }"}},e.prototype.stringifyArray=function(e){for(var n="",t=0,r=e;t<r.length;t++){var i=r[t];n+=""+this.stringify(i)}return n},e.prototype.stringifyObject=function(e){if("Object"!==r.type(e))return"";for(var n=Object.keys(e),t="",i=0,u=n;i<u.length;i++){var o=u[i];t+=this.stringify(o)+": "+this.stringify(e[o])}return t||" "},e.prototype.get=function(e){return(this.store.get(this.stringify(e))||[])[1]},e.prototype.set=function(e,n){return void this.store.set(this.stringify(e),[e,n]),this},e.prototype.has=function(e){return this.store.has(this.stringify(e))},e.prototype.delete=function(e){return this.store.delete(this.stringify(e))},e.prototype.clear=function(){return this.store.clear()},Object.defineProperty(e.prototype,"size",{get:function(){return this.store.size},enumerable:!0,configurable:!0}),e}();n.DataMap=u}),define("src/lib/tick",["require","exports"],function(e,n){"use strict";var t;!function(e){function n(e){void i.push(e),void r()}function t(){void r(),void--u;for(var e=i.length;e-- >0;)void i.shift()()}function r(){if(0!==i.length)for(;u<o.length;)void setTimeout(t,o[u%o.length]),void++u}e.queue=n;var i=[],u=0,o=[0,4,10,20,25].reverse()}(t||(t={}));var r=Function("return typeof process === 'object' && typeof window !== 'object'")();n.Tick=r?Function("return fn => process.nextTick(fn)")():t.queue}),define("src/lib/thenable",["require","exports"],function(e,n){"use strict";function t(e){return!!e&&"object"==typeof e&&"function"==typeof e.then}n.isThenable=t}),define("src/lib/noop",["require","exports"],function(e,n){"use strict";function t(){}n.noop=t}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/collection/datamap","src/lib/tick","src/lib/thenable","src/lib/concat","src/lib/noop"],function(e,n,t,r,i,u,o,c){"use strict";function s(e,n){if(e===n)return!0;if(e.length!==n.length)return!1;for(var t=0;t<e.length;++t)if(e[t]!==n[t])return!1;return!0}var a=function(){function e(n){var i=this,u=void 0===n?{}:n,o=u.name,s=void 0===o?"":o,a=u.dependencies,f=void 0===a?[]:a,d=u.retry,l=void 0!==d&&d,p=u.timeout,h=void 0===p?0:p,v=u.destructor,m=void 0===v?c.noop:v;if(this.deps=new r.DataMap,this.events={exec:new t.Observable,fail:new t.Observable,loss:new t.Observable,exit:new t.Observable},this.procs=new t.Observable,this.alive=!0,this.registerable=!0,this.scheduled=!1,this.workerSharedResource={procs:this.procs,dependenciesStack:[]},this.queue=[],this.constructor===e)throw new Error("Spica: Supervisor: Cannot instantiate abstract classes.");this.name=s,void f.reduce(function(e,n){var t=n[0],r=n[1];return void i.deps.set(t,r)},void 0),this.retry=l,this.timeout=h,this.destructor_=m,void++this.constructor.count}return e.prototype.destructor=function(e){for(void this.checkState(),this.alive=!1;this.queue.length>0;){var n=this.queue.shift(),t=n[0],r=n[1];void this.events.loss.emit(t,[t,r])}try{void this.destructor_(e)}catch(e){void console.error(e)}void--this.constructor.count,void Object.freeze(this)},e.prototype.schedule=function(){var e=this;this.alive&&(this.scheduled||(void i.Tick(function(n){e.alive&&(e.scheduled=!1,void e.drain())}),this.scheduled=!0))},e.prototype.register=function(e,n){if(void this.checkState(),!this.registerable)throw new Error("Spica: Supervisor: Supervisor "+this.name+" cannot register process during the exiting.");return e=o.concat([],e),void this.schedule(),new d(this,this.workerSharedResource,e,n,this.deps.get(e)||[]).terminate},e.prototype.call=function(e,n,t){var r=this;return void 0===t&&(t=this.timeout),void this.checkState(),e=o.concat([],e),new Promise(function(i,u){void r.queue.push([e,n,function(e){return 0===e.length?void u(n):void i(e)},t,Date.now()]),void r.schedule(),t>0!=!1&&void setTimeout(function(){return void r.drain(e)},t+9)})},e.prototype.cast=function(e,n,t){void 0===t&&(t=this.retry),void this.checkState();var r=this.procs.reflect(e,new f.Call(n));return 0===r.length&&void this.events.fail.emit(e,[e,n]),r.length>0||!t?r:this.cast(e,n,!1)},e.prototype.refs=function(e){return void this.checkState(),this.procs.refs(e).map(function(e){var n=e[1],t=n(new f.Self);return[t.namespace,t.process,t.terminate]})},e.prototype.terminate=function(e,n){void this.checkState(),void 0===e&&(this.registerable=!1),void this.procs.emit(e||[],new f.Exit(n)),void this.procs.off(e||[]),void 0===e&&void this.destructor(n)},e.prototype.checkState=function(){if(!this.alive)throw new Error("Spica: Supervisor: Supervisor "+this.name+" already exited.")},e.prototype.drain=function(e){void 0===e&&(e=[]);for(var n,t=Date.now(),r=function(r){var u=i.queue[r],o=u[0],c=u[1],s=u[2],a=u[3],d=u[4],l=e.every(function(e,n){return e===o[n]})?i.procs.reflect(o,new f.Call(c)):[];if(0===l.length&&void i.events.fail.emit(o,[o,c]),0===l.length&&t<d+a)return n=r,"continue";if(0===r?void i.queue.shift():void i.queue.splice(r,1),void--r,0===l.length&&void i.events.loss.emit(o,[o,c]),!s)return n=r,"continue";try{void s(l)}catch(e){void console.error(e)}n=r},i=this,u=0;u<this.queue.length;++u)r(u),u=n},e.count=0,e.procs=0,e}();n.Supervisor=a;var f;!function(e){var n=function(){function e(){void this.WORKER_COMMAND}return e}(),t=function(e){function n(){e.call(this),void this.COMMAND}return __extends(n,e),n}(n);e.Self=t;var r=function(e){function n(n){e.call(this),this.namespace=n,void this.COMMAND}return __extends(n,e),n}(n);e.Deps=r;var i=function(e){function n(n){e.call(this),this.data=n,void this.COMMAND}return __extends(n,e),n}(n);e.Call=i;var u=function(e){function n(n){e.call(this),this.reason=n,void this.COMMAND}return __extends(n,e),n}(n);e.Exit=u}(f||(f={}));var d=function(){function e(n,t,r,i,u){var o=this;this.sv=n,this.sharedResource=t,this.namespace=r,this.process=i,this.dependencies=u,this.alive=!0,this.called=!1,this.concurrency=1,this.receive=function(n){return e.prototype.receive.call(o,n)},this.terminate=function(n){return e.prototype.terminate.call(o,n)},this.sharedResource.allRefsCache=void 0,void++this.sv.constructor.procs,void this.sharedResource.procs.on(r,this.receive)}return e.prototype.destructor=function(e){this.alive&&(void this.sharedResource.procs.off(this.namespace,this.receive),this.alive=!1,void--this.sv.constructor.procs,this.sharedResource.allRefsCache=void 0,void Object.freeze(this),void this.sv.events.exit.emit(this.namespace,[this.namespace,this.process,e]))},e.prototype.tryDependencyResolving=function(){if(this.receive(new f.Deps(this.namespace)))return void(this.sharedResource.dependenciesStack=[]);throw void(this.sharedResource.dependenciesStack=[])},e.prototype.receive=function(e){var n=this;if(void this.checkState(),e instanceof f.Self)return this;if(e instanceof f.Deps){if(e.namespace.length!==this.namespace.length)return!1;if(0===this.concurrency)return!1;for(var t=0,r=this.sharedResource.dependenciesStack;t<r.length;t++){var i=r[t];if(s(this.namespace,i))return!0}return void this.sharedResource.dependenciesStack.push(this.namespace),this.dependencies.every(function(e){return(n.sharedResource.allRefsCache=n.sharedResource.allRefsCache||n.sharedResource.procs.refs([])).some(function(n){var t=n[0],r=n[1];return s(t,e)&&!!r(new f.Deps(e))})})}if(e instanceof f.Call){if(0===this.concurrency)throw void 0;void this.tryDependencyResolving(),this.called||(this.called=!0,void this.sv.events.exec.emit(this.namespace,[this.namespace,this.process]));try{void--this.concurrency;var o=(0,this.process)(e.data);return u.isThenable(o)?void o.then(function(e){void n.sv.schedule(),n.alive&&void++n.concurrency},function(e){void n.sv.schedule(),n.alive&&(void++n.concurrency,void n.terminate(e))}):void++this.concurrency,o}catch(e){throw void void this.terminate(e)}}if(e instanceof f.Exit)throw void void this.terminate(e.reason);throw new TypeError("Spica: Supervisor: Invalid command: "+e)},e.prototype.terminate=function(e){void this.destructor(e)},e.prototype.checkState=function(){if(!this.alive)throw new Error("Spica: Supervisor: Process "+this.namespace+"/"+this.process+" already exited.")},e}()}),define("src/lib/monad/lazy",["require","exports"],function(e,n){"use strict";var t=function(){function e(e){this.thunk=e}return e.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},e}();n.Lazy=t}),define("src/lib/monad/functor",["require","exports","src/lib/monad/lazy"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n}(t.Lazy);n.Functor=r;var r;!function(e){function n(e,n){return n?e.fmap(n):function(n){return e.fmap(n)}}e.fmap=n}(r=n.Functor||(n.Functor={}))}),define("src/lib/curry",["require","exports"],function(e,n){"use strict";function t(e,n,r){return e.length===n.length?e.apply(r,n):function(){for(var i=[],u=0;u<arguments.length;u++)i[u-0]=arguments[u];return t(e,n.concat(i),r)}}n.curry=function(e,n){return 0===e.length?function(){return e.call(n)}:t(e,[],n)}}),define("src/lib/monad/applicative",["require","exports","src/lib/monad/functor","src/lib/curry"],function(e,n,t,r){"use strict";var i=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n}(t.Functor);n.Applicative=i;var i;!function(e){function n(e,t){return t?e.bind(function(e){return t.fmap(function(n){return 0===e.length?e(n):r.curry(e)(n)})}):function(t){return n(e,t)}}e.ap=n}(i=n.Applicative||(n.Applicative={}))}),define("src/lib/monad/monad",["require","exports","src/lib/monad/applicative"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n}(t.Applicative);n.Monad=r;var r;!function(e){function n(e,t){return t?e.bind(t):function(t){return n(e,t)}}e.bind=n}(r=n.Monad||(n.Monad={}))}),define("src/lib/monad/monadplus",["require","exports","src/lib/monad/monad"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n}(t.Monad);n.MonadPlus=r;var r;!function(e){}(r=n.MonadPlus||(n.MonadPlus={}))}),define("src/lib/monad/maybe.impl",["require","exports","src/lib/monad/monadplus"],function(e,n,t){"use strict";function r(){throw new Error("Spica: Maybe: Invalid thunk call.")}var i=function(e){function n(n){e.call(this,n),void this.MAYBE}return __extends(n,e),n.prototype.fmap=function(e){return this.bind(function(n){return new u(e(n))})},n.prototype.ap=function(e){return n.ap(this,e)},n.prototype.bind=function(e){var t=this;return new n(function(){var r=t.evaluate();if(r instanceof u)return e(r.extract());if(r instanceof o)return r;if(r instanceof n)return r.bind(e);throw new TypeError("Spica: Maybe: Invalid monad value.\n\t"+r)})},n.prototype.extract=function(e,n){return n?this.fmap(n).extract(e):this.evaluate().extract(e)},n}(t.MonadPlus);n.Maybe=i;var i;!function(e){function n(e){return new u(e)}e.pure=n,e.Return=n}(i=n.Maybe||(n.Maybe={}));var u=function(e){function n(n){e.call(this,r),this.a=n,void this.JUST}return __extends(n,e),n.prototype.bind=function(e){var n=this;return new i(function(){return e(n.extract())})},n.prototype.extract=function(e,n){return n?n(this.a):this.a},n}(i);n.Just=u;var o=function(e){function n(){e.call(this,r),void this.NOTHING}return __extends(n,e),n.prototype.bind=function(e){return this},n.prototype.extract=function(e){if(!e)throw void 0;return e()},n}(i);n.Nothing=o;var i;!function(e){function n(n,t){return new e(function(){return n.fmap(function(){return n}).extract(function(){return t})})}e.mzero=new o,e.mplus=n}(i=n.Maybe||(n.Maybe={}))}),define("src/lib/monad/maybe",["require","exports","src/lib/monad/maybe.impl"],function(e,n,t){"use strict";function r(e){return new t.Just(e)}var i;!function(e){e.fmap=t.Maybe.fmap,e.pure=t.Maybe.pure,e.ap=t.Maybe.ap,e.Return=t.Maybe.Return,e.bind=t.Maybe.bind,e.mzero=t.Maybe.mzero,e.mplus=t.Maybe.mplus}(i=n.Maybe||(n.Maybe={})),n.Just=r,n.Nothing=t.Maybe.mzero}),define("src/lib/monad/either.impl",["require","exports","src/lib/monad/monad"],function(e,n,t){"use strict";function r(){throw new Error("Spica: Either: Invalid thunk call.")}var i=function(e){function n(n){e.call(this,n),void this.EITHER}return __extends(n,e),n.prototype.fmap=function(e){return this.bind(function(n){return new o(e(n))})},n.prototype.ap=function(e){return n.ap(this,e)},n.prototype.bind=function(e){var t=this;return new n(function(){var r=t.evaluate();if(r instanceof u)return r;if(r instanceof o)return e(r.extract());if(r instanceof n)return r.bind(e);throw new TypeError("Spica: Either: Invalid monad value.\n\t"+r)})},n.prototype.extract=function(e,n){return n?this.fmap(n).extract(e):this.evaluate().extract(e)},n}(t.Monad);n.Either=i;var i;!function(e){function n(e){return new o(e)}e.pure=n,e.Return=n}(i=n.Either||(n.Either={}));var u=function(e){function n(n){e.call(this,r),this.a=n,void this.LEFT}return __extends(n,e),n.prototype.bind=function(e){return this},n.prototype.extract=function(e){if(!e)throw this.a;return e(this.a)},n}(i);n.Left=u;var o=function(e){function n(n){e.call(this,r),this.b=n,void this.RIGHT}return __extends(n,e),n.prototype.bind=function(e){var n=this;return new i(function(){return e(n.extract())})},n.prototype.extract=function(e,n){return n?n(this.b):this.b},n}(i);n.Right=o}),define("src/lib/monad/either",["require","exports","src/lib/monad/either.impl"],function(e,n,t){"use strict";function r(e){return new t.Left(e)}function i(e){return new t.Right(e)}var u;!function(e){e.fmap=t.Either.fmap,e.pure=t.Either.pure,e.ap=t.Either.ap,e.Return=t.Either.Return,e.bind=t.Either.bind}(u=n.Either||(n.Either={})),n.Left=r,n.Right=i}),define("src/lib/cancelable",["require","exports","src/lib/noop","src/lib/monad/maybe","src/lib/monad/either"],function(e,n,t,r,i){"use strict";var u=function(){function e(){var e=this;this.canceled=!1,this.listeners=new Set,this.promise=function(n){return e.canceled?e.promise_=e.promise_||new Promise(function(n,t){return void t(e.reason)}):Promise.resolve(n)},this.maybe=function(n){return e.canceled?r.Nothing:r.Just(n)},this.either=function(n){return e.canceled?i.Left(e.reason):i.Right(n)},this.cancel=function(n){return e.cancel=t.noop,e.canceled=!0,e.reason=n,e.listeners.forEach(function(e){return void e(n)}),e.listeners.clear(),void(e.listeners.add=function(n){return void n(e.reason),e.listeners})}}return e}();n.Cancelable=u}),define("src/lib/monad/sequence/core",["require","exports","src/lib/monad/monadplus"],function(e,n,t){"use strict";function r(){throw new Error("Spica: Sequence: Invalid thunk call.")}var i=function(e){function n(n){e.call(this,r),this.cons=n}return __extends(n,e),n.prototype[Symbol.iterator]=function(){var e=this,t=function(){return e.iterate()};return{next:function(){var e=t();return t=n.Thunk.iterator(e),{done:!n.isIterable(e),value:n.Thunk.value(e)}}}},n}(t.MonadPlus);n.Sequence=i;var i;!function(e){}(i=n.Sequence||(n.Sequence={}));var i;!function(e){function n(e){return r.iterator(e)!==i.done}var t;!function(n){function t(n,t){switch(arguments.length){case 0:return[];case 1:return[n];case 2:return[n,t];default:throw e.Exception.invalidConsError(arguments)}}n.cons=t}(t=e.Data||(e.Data={}));var r;!function(e){function n(e){return e[0]}function t(e){return e[1]}function r(e){return e[2]}e.value=n,e.iterator=t,e.index=r}(r=e.Thunk||(e.Thunk={}));var i;!function(n){function t(n,i,u){return e.isIterable(n)?u(n,function(){return t(r.iterator(n)(),i,u)}):i(n)}n.done=function(){return[void 0,n.done,-1]},n.when=t}(i=e.Iterator||(e.Iterator={})),e.isIterable=n;var u;!function(e){function n(e){return console.error(e,e.length,e[0],e[1]),new TypeError("Spica: Sequence: Invalid parameters of cons.")}function t(e){return console.error(e),new TypeError("Spica: Sequence: Invalid data.")}function r(e){return console.error(e),new TypeError("Spica: Sequence: Invalid thunk.")}e.invalidConsError=n,e.invalidDataError=t,e.invalidThunkError=r}(u=e.Exception||(e.Exception={}))}(i=n.Sequence||(n.Sequence={}))}),define("src/lib/monad/sequence/member/static/resume",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.resume=function(e){return new t.Sequence(function(n,r){return void 0===n&&(n=e),t.Sequence.Iterator.when(n(),function(){return r()},function(e){return r(t.Sequence.Thunk.value(e),t.Sequence.Thunk.iterator(e))})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/from",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.from=function(e){return new t.Sequence(function(n,t){var r=void 0===n?[e[Symbol.iterator](),0]:n,i=r[0],u=r[1],o=i.next();return o.done?t():t(o.value,[i,u+1])}).reduce()},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/cycle",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.cycle=function(e){return new t.Sequence(function n(t,r){var i=void 0===t?[e[Symbol.iterator](),0]:t,u=i[0],o=i[1],c=u.next();return c.done?n([e[Symbol.iterator](),o+1],r):r(c.value,[u,o+1])}).reduce()},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/random",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.random=function(e){return void 0===e&&(e=function(){return Math.random()}),"function"==typeof e?t.Sequence.from(new t.Sequence(function(n,t){return t(e(),n)})):this.random().map(function(n){return e[n*e.length|0]})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/concat",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.concat=function(e){return new t.Sequence(function(n,r){var i=void 0===n?[function(){return e.iterate()},t.Sequence.Iterator.done]:n,u=i[0],o=i[1];return t.Sequence.Iterator.when(u(),function(){return r()},function(e,n){return o=o===t.Sequence.Iterator.done?function(){return t.Sequence.Thunk.value(e).iterate()}:o,t.Sequence.Iterator.when(o(),function(){return o=t.Sequence.Iterator.done,n()},function(n){return r(t.Sequence.Thunk.value(n),[function(){return e},t.Sequence.Thunk.iterator(n)])})})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/zip",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.zip=function(e,n){return new t.Sequence(function(r,i){var u=void 0===r?[function(){return e.iterate()},function(){return n.iterate()}]:r,o=u[0],c=u[1];return t.Sequence.Iterator.when(o(),function(){return i()},function(e){return t.Sequence.Iterator.when(c(),function(){return i()},function(n){return i([t.Sequence.Thunk.value(e),t.Sequence.Thunk.value(n)],[t.Sequence.Thunk.iterator(e),t.Sequence.Thunk.iterator(n)])})})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/difference",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.difference=function(e,n,r){return new t.Sequence(function(i,u){var o=void 0===i?[function(){return e.iterate()},function(){return n.iterate()}]:i,c=o[0],s=o[1];return t.Sequence.Iterator.when(c(),function(){return t.Sequence.Iterator.when(s(),function(){return u()},function(e){return u(t.Sequence.Thunk.value(e),[t.Sequence.Iterator.done,t.Sequence.Thunk.iterator(e)])})},function(e,n){return t.Sequence.Iterator.when(s(),function(){return u(t.Sequence.Thunk.value(e),[t.Sequence.Thunk.iterator(e),t.Sequence.Iterator.done])},function(i){var o=r(t.Sequence.Thunk.value(e),t.Sequence.Thunk.value(i));return o<0?u(t.Sequence.Thunk.value(e),[t.Sequence.Thunk.iterator(e),function(){return i}]):o>0?u(t.Sequence.Thunk.value(i),[function(){return e},t.Sequence.Thunk.iterator(i)]):(s=function(){return t.Sequence.Thunk.iterator(i)()},n())})})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/union",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.union=function(e,n,r){return new t.Sequence(function(i,u){var o=void 0===i?[function(){return e.iterate()},function(){return n.iterate()}]:i,c=o[0],s=o[1];return t.Sequence.Iterator.when(c(),function(){return t.Sequence.Iterator.when(s(),function(){return u()},function(e){return u(t.Sequence.Thunk.value(e),[t.Sequence.Iterator.done,t.Sequence.Thunk.iterator(e)])})},function(e){return t.Sequence.Iterator.when(s(),function(){return u(t.Sequence.Thunk.value(e),[t.Sequence.Thunk.iterator(e),t.Sequence.Iterator.done])},function(n){var i=r(t.Sequence.Thunk.value(e),t.Sequence.Thunk.value(n));return i<0?u(t.Sequence.Thunk.value(e),[t.Sequence.Thunk.iterator(e),function(){return n}]):i>0?u(t.Sequence.Thunk.value(n),[function(){return e},t.Sequence.Thunk.iterator(n)]):u(t.Sequence.Thunk.value(e),[t.Sequence.Thunk.iterator(e),t.Sequence.Thunk.iterator(n)])})})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/intersect",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.intersect=function(e,n,r){return new t.Sequence(function(i,u){var o=void 0===i?[function(){return e.iterate()},function(){return n.iterate()}]:i,c=o[0],s=o[1];return t.Sequence.Iterator.when(c(),function(){return u()},function(e,n){return t.Sequence.Iterator.when(s(),function(){return u()},function(i,o){var c=r(t.Sequence.Thunk.value(e),t.Sequence.Thunk.value(i));return c<0?(s=function(){return i},n()):c>0?o():u(t.Sequence.Thunk.value(e),[t.Sequence.Thunk.iterator(e),t.Sequence.Thunk.iterator(i)])})})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/pure",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.pure=function(e){return new t.Sequence(function(n,t){return t(e)})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/return",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.Return=function(e){return new t.Sequence(function(n,t){return t(e)})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/mempty",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.mempty=new t.Sequence(function(e,n){return n()}),n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/mconcat",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";function r(e,n){return new t.Sequence(function(r,i){var u=void 0===r?[function(){return e.iterate()},function(){return n.iterate()}]:r,o=u[0],c=u[1];return t.Sequence.Iterator.when(o(),function(){return t.Sequence.Iterator.when(c(),function(){return i()},function(e){return i(t.Sequence.Thunk.value(e),[t.Sequence.Iterator.done,t.Sequence.Thunk.iterator(e)])})},function(e){return i(t.Sequence.Thunk.value(e),[t.Sequence.Thunk.iterator(e),c])})})}var i=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.mconcat=function(e){return Array.from(e).reduce(function(e,n){return r(e,n)},t.Sequence.mempty)},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=i}),define("src/lib/monad/sequence/member/static/mappend",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.mappend=function(e,n){return t.Sequence.mconcat([e,n])},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/mzero",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.mzero=t.Sequence.mempty,n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/mplus",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.mplus=t.Sequence.mappend,n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/extract",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,n,t,r){"use strict";var i=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.extract=function(){for(var e=this,n=[],i=function(){return e.iterate()};;){var u=i();if(!t.Sequence.isIterable(u))return n;void r.concat(n,[t.Sequence.Thunk.value(u)]),i=t.Sequence.Thunk.iterator(u)}},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=i}),define("src/lib/monad/sequence/member/instance/iterate",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.iterate=function(){return this.iterate_()},n.prototype.iterate_=function(e,n){var r=this;void 0===n&&(n=0);var i=this.cons(e,t.Sequence.Data.cons);switch(i.length){case 0:return[void 0,t.Sequence.Iterator.done,-1];case 1:return[i[0],function(){return t.Sequence.Iterator.done()},n];case 2:return[i[0],function(){return r.iterate_(i[1],n+1)},n];default:throw t.Sequence.Exception.invalidDataError(i)}},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/memoize",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=new WeakMap,i=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.memoize=function(){var e=this;return new t.Sequence(function(n,i){var u=void 0===n?[0,r.get(e)||r.set(e,new Map).get(e)]:n,o=u[0],c=u[1];return t.Sequence.Iterator.when(c.get(o)||c.set(o,o>0&&c.has(o-1)?t.Sequence.Thunk.iterator(c.get(o-1))():e.iterate()).get(o),function(){ | ||
return i()},function(e){return i(t.Sequence.Thunk.value(e),[o+1,c])})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=i}),define("src/lib/monad/sequence/member/instance/reduce",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.reduce=function(){var e=this;return new t.Sequence(function(n,r){var i=void 0===n?[0,new Map]:n,u=i[0],o=i[1];return t.Sequence.Iterator.when(o.get(u)||o.set(u,u>0&&o.has(u-1)?t.Sequence.Thunk.iterator(o.get(u-1))():e.iterate()).get(u),function(){return r()},function(e){return r(t.Sequence.Thunk.value(e),[u+1,o])})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/take",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.take=function(e){var n=this;return new t.Sequence(function(r,i){return void 0===r&&(r=function(){return n.iterate()}),t.Sequence.Iterator.when(e>0?r():t.Sequence.Iterator.done(),function(){return i()},function(n){return t.Sequence.Thunk.index(n)+1<e?i(t.Sequence.Thunk.value(n),t.Sequence.Thunk.iterator(n)):i(t.Sequence.Thunk.value(n))})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/drop",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.drop=function(e){var n=this;return new t.Sequence(function(r,i){return void 0===r&&(r=function(){return n.iterate()}),t.Sequence.Iterator.when(r(),function(){return i()},function(n,r){return t.Sequence.Thunk.index(n)<e?r():i(t.Sequence.Thunk.value(n),t.Sequence.Thunk.iterator(n))})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/takeWhile",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.takeWhile=function(e){var n=this;return new t.Sequence(function(r,i){return void 0===r&&(r=function(){return n.iterate()}),t.Sequence.Iterator.when(r(),function(){return i()},function(n){return e(t.Sequence.Thunk.value(n))?i(t.Sequence.Thunk.value(n),t.Sequence.Thunk.iterator(n)):i()})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/dropWhile",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.dropWhile=function(e){var n=this;return new t.Sequence(function(r,i){return void 0===r&&(r=function(){return n.iterate()}),t.Sequence.Iterator.when(r(),function(){return i()},function(n,r){return e(t.Sequence.Thunk.value(n))?r():i(t.Sequence.Thunk.value(n),t.Sequence.Thunk.iterator(n))})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/takeUntil",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.takeUntil=function(e){var n=this;return new t.Sequence(function(r,i){return void 0===r&&(r=function(){return n.iterate()}),t.Sequence.Iterator.when(r(),function(){return i()},function(n){return e(t.Sequence.Thunk.value(n))?i(t.Sequence.Thunk.value(n)):i(t.Sequence.Thunk.value(n),t.Sequence.Thunk.iterator(n))})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/dropUntil",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.dropUntil=function(e){var n=this;return new t.Sequence(function(r,i){return void 0===r&&(r=function(){return n.iterate()}),t.Sequence.Iterator.when(r(),function(){return i()},function(n,r){return e(t.Sequence.Thunk.value(n))?r():i(t.Sequence.Thunk.value(n),t.Sequence.Thunk.iterator(n))})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/fmap",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.fmap=function(e){var n=this;return new t.Sequence(function(r){return void 0===r&&(r=function(){return n.iterate()}),t.Sequence.Iterator.when(r(),function(){return t.Sequence.Data.cons()},function(n){return t.Sequence.Data.cons(e(t.Sequence.Thunk.value(n)),t.Sequence.Thunk.iterator(n))})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/ap",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.ap=function(e){return t.Sequence.ap(this,e)},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/bind",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.bind=function(e){return t.Sequence.concat(this.fmap(e))},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/mapM",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,n,t,r){"use strict";var i=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.mapM=function(e){var n=this;return t.Sequence.from([0]).bind(function(){var i=n.extract();switch(i.length){case 0:return t.Sequence.mempty;default:var u=i.shift();return e(u).bind(function(n){return 0===i.length?t.Sequence.from([[n]]):t.Sequence.from(i).mapM(e).fmap(function(e){return r.concat([n],e)})})}})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=i}),define("src/lib/monad/sequence/member/instance/filterM",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,n,t,r){"use strict";var i=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.filterM=function(e){var n=this;return t.Sequence.from([0]).bind(function(){var i=n.extract();switch(i.length){case 0:return t.Sequence.from([[]]);default:var u=i.shift();return e(u).bind(function(n){return n?0===i.length?t.Sequence.from([[u]]):t.Sequence.from(i).filterM(e).fmap(function(e){return r.concat([u],e)}):0===i.length?t.Sequence.from([[]]):t.Sequence.from(i).filterM(e)})}})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=i}),define("src/lib/monad/sequence/member/instance/map",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.map=function(e){var n=this;return new t.Sequence(function(r){return void 0===r&&(r=function(){return n.iterate()}),t.Sequence.Iterator.when(r(),function(){return t.Sequence.Data.cons()},function(n){return t.Sequence.Data.cons(e(t.Sequence.Thunk.value(n),t.Sequence.Thunk.index(n)),t.Sequence.Thunk.iterator(n))})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/filter",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.filter=function(e){var n=this;return new t.Sequence(function(r,i){return void 0===r&&(r=function(){return n.iterate()}),t.Sequence.Iterator.when(r(),function(){return i()},function(n,r){return e(t.Sequence.Thunk.value(n),t.Sequence.Thunk.index(n))?i(t.Sequence.Thunk.value(n),t.Sequence.Thunk.iterator(n)):r()})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/scan",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.scan=function(e,n){var r=this;return new t.Sequence(function(i){var u=void 0===i?[n,function(){return r.iterate()},0]:i,o=u[0],c=u[1],s=u[2];return t.Sequence.Iterator.when(c(),function(){return 0===s?t.Sequence.Data.cons(n):t.Sequence.Data.cons()},function(n){return t.Sequence.Data.cons(o=e(o,t.Sequence.Thunk.value(n)),[o,t.Sequence.Thunk.iterator(n),t.Sequence.Thunk.index(n)+1])})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/fold",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.fold=function(e,n){var r=this;return new t.Sequence(function(i){return void 0===i&&(i=function(){return r.reduce().iterate()}),t.Sequence.Iterator.when(i(),function(){return t.Sequence.Data.cons(n)},function(r){return t.Sequence.Data.cons(e(t.Sequence.Thunk.value(r),t.Sequence.resume(t.Sequence.Thunk.iterator(r)).fold(e,n)))})}).bind(function(e){return e})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/instance/group",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,n,t,r){"use strict";var i=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.group=function(e){var n=this;return new t.Sequence(function(i,u){var o=void 0===i?[function(){return n.iterate()},[]]:i,c=o[0],s=o[1];return t.Sequence.Iterator.when(c(),function(){return 0===s.length?u():u(s)},function(n,i){return 0===s.length||e(s[0],t.Sequence.Thunk.value(n))?(r.concat(s,[t.Sequence.Thunk.value(n)]),i()):u(s,[t.Sequence.Thunk.iterator(n),r.concat([],[t.Sequence.Thunk.value(n)])])})})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=i}),define("src/lib/monad/sequence/member/instance/subsequences",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,n,t,r){"use strict";function i(e){return t.Sequence.Iterator.when(e.iterate(),function(){return t.Sequence.mempty},function(e){return t.Sequence.mappend(t.Sequence.from([[t.Sequence.Thunk.value(e)]]),new t.Sequence(function(n,u){return t.Sequence.Iterator.when(e,function(){return u()},function(e){return u(i(t.Sequence.resume(t.Sequence.Thunk.iterator(e))).fold(function(n,i){return t.Sequence.mappend(t.Sequence.mappend(t.Sequence.from([n]),t.Sequence.from([r.concat([t.Sequence.Thunk.value(e)],n)])),i)},t.Sequence.mempty))})}).bind(function(e){return e}))})}var u=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.subsequences=function(){var e=this;return t.Sequence.mappend(t.Sequence.from([[]]),t.Sequence.from([0]).bind(function(){return i(e)}))},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=u}),define("src/lib/monad/sequence/member/instance/permutations",["require","exports","src/lib/monad/sequence/core"],function(e,n,t){"use strict";function r(e,n){return t.Sequence.Iterator.when(e.iterate(),function(){return t.Sequence.mempty},function(e){return new t.Sequence(function(i,u){return t.Sequence.Iterator.when(e,function(){return u()},function(e){function i(e,n){return o(function(e){return e},e,n)[1]}function o(e,n,r){return t.Sequence.Iterator.when(n.iterate(),function(){return[s,r]},function(n){var i=t.Sequence.Thunk.value(n),u=o(function(n){return e(t.Sequence.mappend(t.Sequence.from([i]),n))},t.Sequence.resume(t.Sequence.Thunk.iterator(n)),r),s=u[0],a=u[1];return[t.Sequence.mappend(t.Sequence.from([i]),s),t.Sequence.mappend(t.Sequence.from([e(t.Sequence.mappend(t.Sequence.from([c]),t.Sequence.mappend(t.Sequence.from([i]),s))).extract()]),a)]})}var c=t.Sequence.Thunk.value(e),s=t.Sequence.resume(t.Sequence.Thunk.iterator(e)).memoize();return u(n.permutations().fold(function(e,n){return i(t.Sequence.from(e),n)},r(s,t.Sequence.mappend(t.Sequence.from([c]),n))))})}).bind(function(e){return e})})}var i=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.permutations=function(){var e=this;return t.Sequence.from([0]).bind(function(){var n=e.extract();return 0===n.length?t.Sequence.mempty:t.Sequence.from([n])}).bind(function(e){return t.Sequence.mappend(t.Sequence.from([e]),r(t.Sequence.from(e),t.Sequence.mempty))})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=i}),define("src/lib/assign",["require","exports","src/lib/type"],function(e,n,t){"use strict";function r(e){return function(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(void 0===n||null===n)throw new TypeError("Spica: assign: Cannot walk on "+n+".");for(var i=0,u=t;i<u.length;i++){var o=u[i];if(void 0!==o&&null!==o)for(var c=0,s=Object.keys(Object(o));c<s.length;c++){var a=s[c],f=Object.getOwnPropertyDescriptor(Object(o),a);void 0!==f&&f.enumerable&&void e(a,Object(n),Object(o))}}return Object(n)}}n.assign=r(function(e,n,t){return n[e]=t[e]}),n.clone=r(function(e,r,i){switch(t.type(i[e])){case"Array":return r[e]=n.clone([],i[e]);case"Object":return r[e]=n.clone({},i[e]);default:return r[e]=i[e]}}),n.extend=r(function(e,r,i){switch(t.type(i[e])){case"Array":return r[e]=n.extend([],i[e]);case"Object":switch(t.type(r[e])){case"Function":case"Object":return r[e]=n.extend(r[e],i[e]);default:return r[e]=n.extend({},i[e])}default:return r[e]=i[e]}})}),define("src/lib/compose",["require","exports","src/lib/assign"],function(e,n,t){"use strict";function r(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return n.reduce(function(e,n){void t.assign(e.prototype,n.prototype);for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r]);return e},e)}n.compose=r}),define("src/lib/monad/sequence",["require","exports","src/lib/monad/sequence/core","src/lib/monad/sequence/member/static/resume","src/lib/monad/sequence/member/static/from","src/lib/monad/sequence/member/static/cycle","src/lib/monad/sequence/member/static/random","src/lib/monad/sequence/member/static/concat","src/lib/monad/sequence/member/static/zip","src/lib/monad/sequence/member/static/difference","src/lib/monad/sequence/member/static/union","src/lib/monad/sequence/member/static/intersect","src/lib/monad/sequence/member/static/pure","src/lib/monad/sequence/member/static/return","src/lib/monad/sequence/member/static/mempty","src/lib/monad/sequence/member/static/mconcat","src/lib/monad/sequence/member/static/mappend","src/lib/monad/sequence/member/static/mzero","src/lib/monad/sequence/member/static/mplus","src/lib/monad/sequence/member/instance/extract","src/lib/monad/sequence/member/instance/iterate","src/lib/monad/sequence/member/instance/memoize","src/lib/monad/sequence/member/instance/reduce","src/lib/monad/sequence/member/instance/take","src/lib/monad/sequence/member/instance/drop","src/lib/monad/sequence/member/instance/takeWhile","src/lib/monad/sequence/member/instance/dropWhile","src/lib/monad/sequence/member/instance/takeUntil","src/lib/monad/sequence/member/instance/dropUntil","src/lib/monad/sequence/member/instance/fmap","src/lib/monad/sequence/member/instance/ap","src/lib/monad/sequence/member/instance/bind","src/lib/monad/sequence/member/instance/mapM","src/lib/monad/sequence/member/instance/filterM","src/lib/monad/sequence/member/instance/map","src/lib/monad/sequence/member/instance/filter","src/lib/monad/sequence/member/instance/scan","src/lib/monad/sequence/member/instance/fold","src/lib/monad/sequence/member/instance/group","src/lib/monad/sequence/member/instance/subsequences","src/lib/monad/sequence/member/instance/permutations","src/lib/compose"],function(e,n,t,r,i,u,o,c,s,a,f,d,l,p,h,v,m,q,b,y,S,_,x,w,k,g,T,M,O,I,j,E,P,R,N,D,A,z,C,L,F,W){"use strict";n.Sequence=t.Sequence,void W.compose(t.Sequence,r.default,i.default,u.default,o.default,c.default,s.default,a.default,f.default,d.default,l.default,p.default,h.default,v.default,m.default,q.default,b.default,y.default,S.default,_.default,x.default,w.default,k.default,g.default,T.default,M.default,O.default,I.default,j.default,E.default,P.default,R.default,N.default,D.default,A.default,z.default,C.default,L.default,F.default)}),define("src/lib/flip",["require","exports","src/lib/curry"],function(e,n,t){"use strict";function r(e){return t.curry(function(n,t){return e.length>1?e(t,n):e(t)(n)})}n.flip=r}),define("src/lib/list",["require","exports","src/lib/concat"],function(e,n,t){"use strict";var r=function(){function e(){void this.NIL}return e.prototype.push=function(e){return new i(e,this)},e.prototype.array=function(){return[]},e}();n.Nil=r;var i=function(){function e(e,n){this.head_=e,this.tail_=n,void this.CONS}return e.prototype.push=function(n){return new e(n,this)},e.prototype.head=function(){return this.head_},e.prototype.tail=function(){return this.tail_},e.prototype.walk=function(e){return void e(this.head()),this.tail()},e.prototype.modify=function(e){return this.tail().push(e(this.head()))},e.prototype.extend=function(e){return this.push(e(this.head()))},e.prototype.compact=function(e){var n=this;return this.tail().modify(function(t){return e(n.head(),t)})},e.prototype.reverse=function(){return this.array().reduce(function(e,n){return e.push(n)},new r)},e.prototype.tuple=function(){return this.array()},e.prototype.array=function(){return t.concat([this.head()],this.tail().array())},e}()}),define("src/lib/hlist",["require","exports","src/lib/concat"],function(e,n,t){"use strict";var r=function(){function e(){void this.NIL}return e.prototype.push=function(e){return new i(e,this)},e.prototype.array=function(){return[]},e}();n.HNil=r;var i=function(){function e(e,n){this.head_=e,this.tail_=n,void this.CONS}return e.prototype.push=function(n){return new e(n,this)},e.prototype.head=function(){return this.head_},e.prototype.tail=function(){return this.tail_},e.prototype.walk=function(e){return void e(this.head()),this.tail()},e.prototype.modify=function(e){return this.tail().push(e(this.head()))},e.prototype.extend=function(e){return this.push(e(this.head()))},e.prototype.compact=function(e){var n=this;return this.tail().modify(function(t){return e(n.head(),t)})},e.prototype.reverse=function(){return this.array().reduce(function(e,n){return e.push(n)},new r)},e.prototype.tuple=function(){return this.array()},e.prototype.array=function(){return t.concat([this.head()],this.tail().array())},e}()}),define("src/lib/collection/attrmap",["require","exports"],function(e,n){"use strict";var t=function(){function e(e,n,t){var r=this;void 0===e&&(e=[]),void 0===n&&(n=WeakMap),void 0===t&&(t=Map),this.KeyMap=n,this.ValueMap=t,this.store=new this.KeyMap,void Array.from(e).forEach(function(e){var n=e[0],t=e[1],i=e[2];return void r.set(n,t,i)})}return e.prototype.get=function(e,n){return this.store.get(e)&&this.store.get(e).get(n)},e.prototype.set=function(e,n,t){var r=this.store.has(e)?this.store.get(e):this.store.set(e,new this.ValueMap).get(e);return void r.set(n,t),this},e.prototype.has=function(e,n){return 1===arguments.length?this.store.has(e):this.store.has(e)&&this.store.get(e).has(n)},e.prototype.delete=function(e,n){return 1===arguments.length?this.store.delete(e):!!this.store.has(e)&&this.store.get(e).delete(n)},e}();n.AttrMap=t}),define("src/lib/mixin",["require","exports","src/lib/assign"],function(e,n,t){"use strict";function r(){for(var e=[],n=0;n<arguments.length;n++)e[n-0]=arguments[n];return e.reduceRight(function(e,n){return i(n,e)},function(){function e(){}return e}())}function i(e,n){var r=function(){function t(){return e.call(n.call(this)||this)}return t}();void t.assign(r.prototype,e.prototype,n.prototype);for(var i in n)n.hasOwnProperty(i)&&(r[i]=n[i]);for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);return r}n.Mixin=r}),define("src/lib/fingerprint",["require","exports"],function(e,n){"use strict";function t(){return i(u([o(window.navigator),o(window.screen),o((new Date).getTimezoneOffset())].join()))}function r(){return i(u([o(process)].join()))}function i(e){return e.split("").reduce(function(e,n,t){return(+n*t+e)%1e9||e-+n},0)}function u(e){return e.split("").map(function(e){return e.charCodeAt(0)}).join("")}function o(e,n){if(void 0===n&&(n=5),n>0&&e&&"object"==typeof e){var t="{";for(var r in e)t+='"'+r+'": '+o(e[r],n-1)+",";return t+="}"}return!e||e.toString?'"'+e+'"':'"'+Object.prototype.toString.call(e)+'"'}n.FINGERPRINT="object"==typeof window?t():r(),n.browser=t,n.server=r,n.hash=i,n.str2digit=u,n.stringify=o}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(e,n,t){"use strict";function r(){var e=o=o*Date.now()%1e15;if(e<16||1e15<e)throw new Error("Spica: uuid: Invalid uuid dynamic seed.");for(var n="",t=0,r=u;t<r.length;t++){var i=r[t];if("x"===i||"y"===i){var c=Math.random()*e%16|0,s="x"==i?c:3&c|8;n+=s.toString(16)}else n+=i}return n.toLowerCase()}var i=t.FINGERPRINT*Date.now()%1e15;if(!i||"number"!=typeof i||i<100||1e15<i)throw new Error("Spica: uuid: Invalid uuid static seed.\n\t"+t.FINGERPRINT);var u=Object.freeze("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split("")),o=i;n.v4=r}),define("src/lib/sort",["require","exports"],function(e,n){"use strict";function t(e,n,t,r){if(void 0===r&&(r=!1),!r&&t*t>1.25*e.length)return e.sort(n);t=t<e.length-1?t:e.length-1;for(var i=0;i<t;++i)for(var u=i+1;u<e.length;++u)if(n(e[i],e[u])>0!=!1){var o=e[i];e[i]=e[u],e[u]=o}return e}n.sort=t}),define("src/export",["require","exports","src/lib/supervisor","src/lib/observable","src/lib/cancelable","src/lib/monad/sequence","src/lib/monad/maybe","src/lib/monad/either","src/lib/curry","src/lib/flip","src/lib/list","src/lib/hlist","src/lib/collection/datamap","src/lib/collection/attrmap","src/lib/mixin","src/lib/tick","src/lib/fingerprint","src/lib/uuid","src/lib/sqid","src/lib/assign","src/lib/concat","src/lib/sort"],function(e,n,t,r,i,u,o,c,s,a,f,d,l,p,h,v,m,q,b,y,S,_){"use strict";n.Supervisor=t.Supervisor,n.Observable=r.Observable,n.Cancelable=i.Cancelable,n.Sequence=u.Sequence,n.Maybe=o.Maybe,n.Just=o.Just,n.Nothing=o.Nothing,n.Either=c.Either,n.Left=c.Left,n.Right=c.Right,n.curry=s.curry,n.flip=a.flip,n.Nil=f.Nil,n.HNil=d.HNil,n.DataMap=l.DataMap,n.AttrMap=p.AttrMap,n.Mixin=h.Mixin,n.Tick=v.Tick,n.FINGERPRINT=m.FINGERPRINT,n.uuid=q.v4,n.sqid=b.sqid,n.assign=y.assign,n.clone=y.clone,n.extend=y.extend,n.concat=S.concat,n.sort=_.sort}),define("spica",["require","exports","src/export","./src/import"],function(e,n,t){"use strict";function r(e){for(var t in e)n.hasOwnProperty(t)||(n[t]=e[t])}r(t)}); | ||
/*! spica v0.0.33 https://github.com/falsandtru/spica | (c) 2016, falsandtru | MIT License */ | ||
define="function"==typeof define&&define.amd?define:function(){"use strict";var e="spica",t={};return function n(r,i,u){return u?void u.apply(this,i.map(function(e){switch(e){case"require":return"function"==typeof require?require:void 0;case"exports":return r.indexOf("/")===-1?t[r]="undefined"==typeof exports?self[r]=self[r]||{}:exports:t[r]=t.hasOwnProperty(r)?t[r]:{};default:return".d"===e.slice(-2)&&{}||t.hasOwnProperty(e)&&t[e]||"function"==typeof require&&require(e)||self[e]}})):void n(e,r,i)}}();var __extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)};define("src/lib/concat",["require","exports"],function(e,t){"use strict";function n(e,t){for(var n=0,r=t.length,i=e.length;n<r;++n)e[n+i]=t[n];return e}t.concat=n}),define("src/lib/observable",["require","exports","src/lib/concat"],function(e,t,n){"use strict";var r=function(){function e(){this.node_={parent:void 0,childrenMap:Object.create(null),childrenList:[],registers:[]}}return e.prototype.monitor=function(e,t,n){var r=this;return void 0===n&&(n=t),void this.throwTypeErrorIfInvalidSubscriber_(t,e),void this.seekNode_(e).registers.push([e,n,!0,t]),function(){return r.off(e,n)}},e.prototype.on=function(e,t,n){var r=this;return void 0===n&&(n=t),void this.throwTypeErrorIfInvalidSubscriber_(t,e),void this.seekNode_(e).registers.push([e,n,!1,function(e){return t(e)}]),function(){return r.off(e,n)}},e.prototype.off=function(e,t){switch(typeof t){case"function":return void this.seekNode_(e).registers.some(function(e,n,r){var i=e[1];if(t!==i)return!1;switch(n){case 0:return!void r.shift();case r.length-1:return!void r.pop();default:return!void r.splice(n,1)}});case"undefined":var n=this.seekNode_(e);return n.childrenMap=Object.create(null),n.childrenList=[],void(n.registers=[]);default:throw this.throwTypeErrorIfInvalidSubscriber_(t,e)}},e.prototype.once=function(e,t){var n=this;return void this.throwTypeErrorIfInvalidSubscriber_(t,e),this.on(e,function(r){return void n.off(e,t),t(r)},t)},e.prototype.emit=function(e,t,n){void this.drain_(e,t,n)},e.prototype.reflect=function(e,t){var n=[];return void this.emit(e,t,function(e,t){return n=t}),n},e.prototype.drain_=function(e,t,n){var r=[];if(void this.refsBelow_(this.seekNode_(e)).reduce(function(e,i){var u=i[2],o=i[3];if(!u)try{var c=o(t);n&&(r[r.length]=c)}catch(e){void 0!==e&&null!==e&&void console.error(e+"")}},void 0),void this.refsAbove_(this.seekNode_(e)).reduce(function(e,n){var r=n[2],i=n[3];if(r)try{void i(t)}catch(e){void 0!==e&&null!==e&&void console.error(e)}},void 0),n)try{void n(t,r)}catch(e){void console.error(e)}},e.prototype.refs=function(e){return this.refsBelow_(this.seekNode_(e))},e.prototype.refsAbove_=function(e){var t=e.parent,r=e.registers;for(r=n.concat([],r);t;)r=n.concat(r,t.registers),t=t.parent;return r},e.prototype.refsBelow_=function(e){var t=e.childrenList,r=e.childrenMap,i=e.registers;i=n.concat([],i);for(var u=0;u<t.length;++u){var o=t[u],c=this.refsBelow_(r[o]);i=n.concat(i,c),0===c.length&&(void delete r[o],void t.splice(t.indexOf(o),1),void--u)}return i},e.prototype.seekNode_=function(e){for(var t=this.node_,n=0,r=e;n<r.length;n++){var i=r[n],u=t.childrenMap;u[i+""]||(void t.childrenList.push(i+""),u[i+""]={parent:t,childrenMap:Object.create(null),childrenList:[],registers:[]}),t=u[i+""]}return t},e.prototype.throwTypeErrorIfInvalidSubscriber_=function(e,t){switch(typeof e){case"function":return;default:throw new TypeError("Spica: Observable: Invalid subscriber.\n\t"+t+" "+e)}},e}();t.Observable=r}),define("src/lib/tick",["require","exports"],function(e,t){"use strict";function n(e){void u.push(e),void i()}function r(){for(var e=u.length;;){try{for(;e>0;)void--e,void u.shift()()}catch(e){console.error(e);continue}break}o=!1}function i(){o||0!==u.length&&(void Promise.resolve().then(r),o=!0)}var u=[],o=!1,c=Function("return typeof process === 'object' && typeof window !== 'object'")();t.Tick=c?Function("return fn => process.nextTick(fn)")():n}),define("src/lib/thenable",["require","exports"],function(e,t){"use strict";function n(e){return!!e&&"object"==typeof e&&"function"==typeof e.then}t.isThenable=n}),define("src/lib/sqid",["require","exports"],function(e,t){"use strict";function n(e){if(arguments.length>0){if("number"!=typeof e)throw new TypeError("Spica: sqid: A parameter value must be a number: "+e);if(e>=0==!1)throw new TypeError("Spica: sqid: A parameter value must be a positive number: "+e);if(e%1!==0)throw new TypeError("Spica: sqid: A parameter value must be an integer: "+e)}return void 0===e?(1e15+ ++r+"").slice(1):(1e15+e+"").slice(1)}var r=0;t.sqid=n}),define("src/lib/noop",["require","exports"],function(e,t){"use strict";function n(){}t.noop=n}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/tick","src/lib/thenable","src/lib/sqid","src/lib/noop"],function(e,t,n,r,i,u,o){"use strict";var c=function(){function e(t){var r=void 0===t?{}:t,i=r.name,c=void 0===i?"":i,s=r.timeout,a=void 0===s?0:s,f=r.destructor,d=void 0===f?o.noop:f;if(this.id=u.sqid(),this.events={init:new n.Observable,loss:new n.Observable,exit:new n.Observable},this.procs=new n.Observable,this.alive=!0,this.registerable=!0,this.scheduled=!1,this.workerSharedResource={procs:this.procs},this.queue=[],this.constructor===e)throw new Error("Spica: Supervisor: <"+this.id+"/"+this.name+">: Cannot instantiate abstract classes.");this.name=c,this.timeout=a,this.destructor_=d,void++this.constructor.count}return e.prototype.destructor=function(e){void this.checkState(),this.alive=!1,void this.drain();try{void this.destructor_(e)}catch(e){void console.error(e)}void--this.constructor.count,void Object.freeze(this)},e.prototype.schedule=function(){var e=this;this.alive&&(this.scheduled||(void r.Tick(function(t){e.alive&&(e.scheduled=!1,void e.drain())}),this.scheduled=!0))},e.prototype.register=function(e,t,n){if(void this.checkState(),!this.registerable)throw new Error("Spica: Supervisor: <"+this.id+"/"+this.name+"/"+e+">: Cannot register a process after a supervisor is terminated.");if(this.procs.refs([e]).length>0)throw new Error("Spica: Supervisor: <"+this.id+"/"+this.name+"/"+e+">: Cannot register a process multiply using the same name.");return void this.schedule(),t="function"==typeof t?{init:function(e){return e},call:t,exit:function(e){}}:t,new a(this,this.workerSharedResource,e,t,n).terminate},e.prototype.call=function(e,t,n,r){var i=this;void 0===r&&(r=this.timeout),void this.checkState(),void this.queue.push([e,t,n,r,Date.now()]),void this.schedule(),r<1/0!=!1&&r>0!=!1&&void setTimeout(function(){return void i.drain(e)},r+9)},e.prototype.cast=function(e,t,n){void 0===n&&(n=this.timeout),void this.checkState();var r=this.procs.reflect([e],new s.Call(t,n));return 0===r.length&&void this.events.loss.emit([e],[e,t]),r.length>0},e.prototype.refs=function(e){return void this.checkState(),this.procs.refs(void 0===e?[]:[e]).map(function(e){var t=e[1],n=t(new s.Self);return[n.name,n.process,n.state,n.terminate]})},e.prototype.terminate=function(e,t){if(this.registerable){void 0===e&&(this.registerable=!1);var n=void 0===e?[]:[e];void this.procs.emit(n,new s.Exit(t)),void this.procs.off(n),void 0===e&&void this.destructor(t)}},e.prototype.checkState=function(){if(!this.alive)throw new Error("Spica: Supervisor: <"+this.id+"/"+this.name+">: A supervisor is already terminated.")},e.prototype.drain=function(e){for(var t,n=this,r=Date.now(),u=function(u){var c=o.queue[u],a=c[0],f=c[1],d=c[2],l=c[3],p=c[4],h=void 0===e||e===a?o.procs.reflect([a],new s.Call(f,p+l-r)):[];if(o.alive&&0===h.length&&r<p+l)return t=u,"continue";if(0===u?void o.queue.shift():void o.queue.splice(u,1),void--u,0===h.length&&void o.events.loss.emit([a],[a,f]),o.alive&&h.length>0){var v=h[0];if(i.isThenable(v))void Promise.resolve(v).then(function(e){return n.alive?void d(e):void d(void 0,new Error("Spica: Supervisor: <"+n.id+"/"+n.name+"/"+a+">: A request is expired."))},function(e){return void d(void 0,e)});else try{void d(v)}catch(e){void console.error(e)}}else void d(void 0,new Error("Spica: Supervisor: <"+o.id+"/"+o.name+"/"+a+">: A request is expired."));t=u},o=this,c=0;c<this.queue.length;++c)u(c),c=t},e}();t.Supervisor=c,c.count=0,c.procs=0,function(e){}(c=t.Supervisor||(t.Supervisor={}));var s;!function(e){var t=function(){function e(){void this.COMMAND}return e}();e.Self=t;var n=function(){function e(e,t){this.param=e,this.timeout=t,void this.COMMAND}return e}();e.Call=n;var r=function(){function e(e){this.reason=e,void this.COMMAND}return e}();e.Exit=r}(s||(s={}));var a=function(){function e(t,n,r,i,u){var o=this;this.sv=t,this.sharedResource=n,this.name=r,this.process=i,this.state=u,this.alive=!0,this.called=!1,this.concurrency=1,this.receive=function(t){return e.prototype.receive.call(o,t)},this.terminate=function(t){return e.prototype.terminate.call(o,t)},void++this.sv.constructor.procs,void this.sharedResource.procs.on([r],this.receive)}return e.prototype.destructor=function(e){if(this.alive){void this.sharedResource.procs.off([this.name],this.receive),this.alive=!1,void--this.sv.constructor.procs,void Object.freeze(this);try{void this.process.exit(this.state,e),void this.sv.events.exit.emit([this.name],[this.name,this.process,this.state,e])}catch(e){void this.sv.events.exit.emit([this.name],[this.name,this.process,this.state,e]),void this.sv.terminate(void 0,e)}}},e.prototype.receive=function(e){var t=this;if(void this.checkState(),e instanceof s.Call){if(0===this.concurrency)throw void 0;try{void--this.concurrency,this.called||(this.called=!0,void this.sv.events.init.emit([this.name],[this.name,this.process,this.state]),this.state=this.process.init(this.state));var n=this.process.call(e.param,this.state);if(i.isThenable(n))return new Promise(function(r,i){void n.then(r,i),e.timeout<1/0!=!1&&void setTimeout(function(){return void i(new Error("Spica: Supervisor: <"+t.sv.id+"/"+t.sv.name+"/"+t.name+">: Timeout while processing."))},e.timeout)}).then(function(e){var n=e[0],r=e[1];if(void++t.concurrency,void t.sv.schedule(),!t.alive)throw void 0;return t.state=r,n},function(e){if(void++t.concurrency,void t.sv.schedule(),!t.alive)throw e;throw void t.terminate(e),e});void++this.concurrency;var r=n[0],u=n[1];return this.state=u,r}catch(e){throw void void this.terminate(e)}}if(e instanceof s.Exit)throw void void this.terminate(e.reason);if(e instanceof s.Self)return this;throw new TypeError("Spica: Supervisor: <"+this.sv.id+"/"+this.sv.name+"/"+this.name+">: Invalid command: "+e)},e.prototype.terminate=function(e){void this.destructor(e)},e.prototype.checkState=function(){if(!this.alive)throw new Error("Spica: Supervisor: <"+this.sv.id+"/"+this.sv.name+"/"+this.name+">: A process is already terminated:\n"+this.process)},e}()}),define("src/lib/monad/lazy",["require","exports"],function(e,t){"use strict";var n=function(){function e(e){this.thunk=e}return e.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},e}();t.Lazy=n}),define("src/lib/monad/functor",["require","exports","src/lib/monad/lazy"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t}(n.Lazy);t.Functor=r,function(e){function t(e,t){return t?e.fmap(t):function(t){return e.fmap(t)}}e.fmap=t}(r=t.Functor||(t.Functor={}))}),define("src/lib/curry",["require","exports"],function(e,t){"use strict";function n(e,t,r){return e.length===t.length?e.apply(r,t):function(){for(var i=[],u=0;u<arguments.length;u++)i[u-0]=arguments[u];return n(e,t.concat(i),r)}}t.curry=function(e,t){return 0===e.length?function(){return e.call(t)}:n(e,[],t)}}),define("src/lib/monad/applicative",["require","exports","src/lib/monad/functor","src/lib/curry"],function(e,t,n,r){"use strict";var i=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t}(n.Functor);t.Applicative=i,function(e){function t(e,n){return n?e.bind(function(e){return n.fmap(function(t){return 0===e.length?e(t):r.curry(e)(t)})}):function(n){return t(e,n)}}e.ap=t}(i=t.Applicative||(t.Applicative={}))}),define("src/lib/monad/monad",["require","exports","src/lib/monad/applicative"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t}(n.Applicative);t.Monad=r,function(e){function t(e,n){return n?e.bind(n):function(n){return t(e,n)}}e.bind=t}(r=t.Monad||(t.Monad={}))}),define("src/lib/monad/monadplus",["require","exports","src/lib/monad/monad"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t}(n.Monad);t.MonadPlus=r,function(e){}(r=t.MonadPlus||(t.MonadPlus={}))}),define("src/lib/monad/maybe.impl",["require","exports","src/lib/monad/monadplus"],function(e,t,n){"use strict";function r(){throw new Error("Spica: Maybe: Invalid thunk call.")}var i=function(e){function t(t){var n=e.call(this,t)||this;return void n.MAYBE,n}return __extends(t,e),t.prototype.fmap=function(e){return this.bind(function(t){return new u(e(t))})},t.prototype.ap=function(e){return t.ap(this,e)},t.prototype.bind=function(e){var n=this;return new t(function(){var r=n.evaluate();if(r instanceof u)return e(r.extract());if(r instanceof o)return r;if(r instanceof t)return r.bind(e);throw new TypeError("Spica: Maybe: Invalid monad value.\n\t"+r)})},t.prototype.extract=function(e,t){return t?this.fmap(t).extract(e):this.evaluate().extract(e)},t}(n.MonadPlus);t.Maybe=i,function(e){function t(e){return new u(e)}e.pure=t,e.Return=t}(i=t.Maybe||(t.Maybe={}));var u=function(e){function t(t){var n=e.call(this,r)||this;return n.a=t,void n.JUST,n}return __extends(t,e),t.prototype.bind=function(e){var t=this;return new i(function(){return e(t.extract())})},t.prototype.extract=function(e,t){return t?t(this.a):this.a},t}(i);t.Just=u;var o=function(e){function t(){var t=e.call(this,r)||this;return void t.NOTHING,t}return __extends(t,e),t.prototype.bind=function(e){return this},t.prototype.extract=function(e){if(!e)throw void 0;return e()},t}(i);t.Nothing=o,function(e){function t(t,n){return new e(function(){return t.fmap(function(){return t}).extract(function(){return n})})}e.mzero=new o,e.mplus=t}(i=t.Maybe||(t.Maybe={}))}),define("src/lib/monad/maybe",["require","exports","src/lib/monad/maybe.impl"],function(e,t,n){"use strict";function r(e){return new n.Just(e)}var i;!function(e){e.fmap=n.Maybe.fmap,e.pure=n.Maybe.pure,e.ap=n.Maybe.ap,e.Return=n.Maybe.Return,e.bind=n.Maybe.bind,e.mzero=n.Maybe.mzero,e.mplus=n.Maybe.mplus}(i=t.Maybe||(t.Maybe={})),t.Just=r,t.Nothing=n.Maybe.mzero}),define("src/lib/monad/either.impl",["require","exports","src/lib/monad/monad"],function(e,t,n){"use strict";function r(){throw new Error("Spica: Either: Invalid thunk call.")}var i=function(e){function t(t){var n=e.call(this,t)||this;return void n.EITHER,n}return __extends(t,e),t.prototype.fmap=function(e){return this.bind(function(t){return new o(e(t))})},t.prototype.ap=function(e){return t.ap(this,e)},t.prototype.bind=function(e){var n=this;return new t(function(){var r=n.evaluate();if(r instanceof u)return r;if(r instanceof o)return e(r.extract());if(r instanceof t)return r.bind(e);throw new TypeError("Spica: Either: Invalid monad value.\n\t"+r)})},t.prototype.extract=function(e,t){return t?this.fmap(t).extract(e):this.evaluate().extract(e)},t}(n.Monad);t.Either=i,function(e){function t(e){return new o(e)}e.pure=t,e.Return=t}(i=t.Either||(t.Either={}));var u=function(e){function t(t){var n=e.call(this,r)||this;return n.a=t,void n.LEFT,n}return __extends(t,e),t.prototype.bind=function(e){return this},t.prototype.extract=function(e){if(!e)throw this.a;return e(this.a)},t}(i);t.Left=u;var o=function(e){function t(t){var n=e.call(this,r)||this;return n.b=t,void n.RIGHT,n}return __extends(t,e),t.prototype.bind=function(e){var t=this;return new i(function(){return e(t.extract())})},t.prototype.extract=function(e,t){return t?t(this.b):this.b},t}(i);t.Right=o}),define("src/lib/monad/either",["require","exports","src/lib/monad/either.impl"],function(e,t,n){"use strict";function r(e){return new n.Left(e)}function i(e){return new n.Right(e)}var u;!function(e){e.fmap=n.Either.fmap,e.pure=n.Either.pure,e.ap=n.Either.ap,e.Return=n.Either.Return,e.bind=n.Either.bind}(u=t.Either||(t.Either={})),t.Left=r,t.Right=i}),define("src/lib/cancelable",["require","exports","src/lib/noop","src/lib/monad/maybe","src/lib/monad/either"],function(e,t,n,r,i){"use strict";var u=function(){function e(){var e=this;this.canceled=!1,this.listeners=new Set,this.promise=function(t){return e.canceled?e.promise_=e.promise_||new Promise(function(t,n){return void n(e.reason)}):Promise.resolve(t)},this.maybe=function(t){return e.canceled?r.Nothing:r.Just(t)},this.either=function(t){return e.canceled?i.Left(e.reason):i.Right(t)},this.cancel=function(t){return e.cancel=n.noop,e.canceled=!0,e.reason=t,e.listeners.forEach(function(e){return void e(t)}),e.listeners.clear(),void(e.listeners.add=function(t){return void t(e.reason),e.listeners})}}return e}();t.Cancelable=u}),define("src/lib/monad/sequence/core",["require","exports","src/lib/monad/monadplus"],function(e,t,n){"use strict";function r(){throw new Error("Spica: Sequence: Invalid thunk call.")}var i=function(e){function t(t){var n=e.call(this,r)||this;return n.cons=t,n}return __extends(t,e),t.prototype[Symbol.iterator]=function(){var e=this,n=function(){return e.iterate()};return{next:function(){var e=n();return n=t.Thunk.iterator(e),{done:!t.isIterable(e),value:t.Thunk.value(e)}}}},t}(n.MonadPlus);t.Sequence=i,function(e){}(i=t.Sequence||(t.Sequence={})),function(e){function t(e){return r.iterator(e)!==i.done}var n;!function(t){function n(t,n){switch(arguments.length){case 0:return[];case 1:return[t];case 2:return[t,n];default:throw e.Exception.invalidConsError(arguments)}}t.cons=n}(n=e.Data||(e.Data={}));var r;!function(e){function t(e){return e[0]}function n(e){return e[1]}function r(e){return e[2]}e.value=t,e.iterator=n,e.index=r}(r=e.Thunk||(e.Thunk={}));var i;!function(t){function n(t,i,u){return e.isIterable(t)?u(t,function(){return n(r.iterator(t)(),i,u)}):i(t)}t.done=function(){return[void 0,t.done,-1]},t.when=n}(i=e.Iterator||(e.Iterator={})),e.isIterable=t;var u;!function(e){function t(e){return console.error(e,e.length,e[0],e[1]),new TypeError("Spica: Sequence: Invalid parameters of cons.")}function n(e){return console.error(e),new TypeError("Spica: Sequence: Invalid data.")}function r(e){return console.error(e),new TypeError("Spica: Sequence: Invalid thunk.")}e.invalidConsError=t,e.invalidDataError=n,e.invalidThunkError=r}(u=e.Exception||(e.Exception={}))}(i=t.Sequence||(t.Sequence={}))}),define("src/lib/monad/sequence/member/static/resume",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.resume=function(e){return new n.Sequence(function(t,r){return void 0===t&&(t=e),n.Sequence.Iterator.when(t(),function(){return r()},function(e){return r(n.Sequence.Thunk.value(e),n.Sequence.Thunk.iterator(e))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/from",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.from=function(e){return new n.Sequence(function(t,n){var r=void 0===t?[e[Symbol.iterator](),0]:t,i=r[0],u=r[1],o=i.next();return o.done?n():n(o.value,[i,u+1])}).reduce()},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/cycle",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.cycle=function(e){return new n.Sequence(function t(n,r){var i=void 0===n?[e[Symbol.iterator](),0]:n,u=i[0],o=i[1],c=u.next();return c.done?t([e[Symbol.iterator](),o+1],r):r(c.value,[u,o+1])}).reduce()},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/random",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.random=function(e){return void 0===e&&(e=function(){return Math.random()}),"function"==typeof e?n.Sequence.from(new n.Sequence(function(t,n){return n(e(),t)})):this.random().map(function(t){return e[t*e.length|0]})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/concat",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.concat=function(e){return new n.Sequence(function(t,r){var i=void 0===t?[function(){return e.iterate()},n.Sequence.Iterator.done]:t,u=i[0],o=i[1];return n.Sequence.Iterator.when(u(),function(){return r()},function(e,t){return o=o===n.Sequence.Iterator.done?function(){return n.Sequence.Thunk.value(e).iterate()}:o,n.Sequence.Iterator.when(o(),function(){return o=n.Sequence.Iterator.done,t()},function(t){return r(n.Sequence.Thunk.value(t),[function(){return e},n.Sequence.Thunk.iterator(t)])})})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/zip",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.zip=function(e,t){return new n.Sequence(function(r,i){var u=void 0===r?[function(){return e.iterate()},function(){return t.iterate()}]:r,o=u[0],c=u[1];return n.Sequence.Iterator.when(o(),function(){return i()},function(e){return n.Sequence.Iterator.when(c(),function(){return i()},function(t){return i([n.Sequence.Thunk.value(e),n.Sequence.Thunk.value(t)],[n.Sequence.Thunk.iterator(e),n.Sequence.Thunk.iterator(t)])})})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/difference",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.difference=function(e,t,r){return new n.Sequence(function(i,u){var o=void 0===i?[function(){return e.iterate()},function(){return t.iterate()}]:i,c=o[0],s=o[1];return n.Sequence.Iterator.when(c(),function(){return n.Sequence.Iterator.when(s(),function(){return u()},function(e){return u(n.Sequence.Thunk.value(e),[n.Sequence.Iterator.done,n.Sequence.Thunk.iterator(e)])})},function(e,t){return n.Sequence.Iterator.when(s(),function(){return u(n.Sequence.Thunk.value(e),[n.Sequence.Thunk.iterator(e),n.Sequence.Iterator.done])},function(i){var o=r(n.Sequence.Thunk.value(e),n.Sequence.Thunk.value(i));return o<0?u(n.Sequence.Thunk.value(e),[n.Sequence.Thunk.iterator(e),function(){return i}]):o>0?u(n.Sequence.Thunk.value(i),[function(){return e},n.Sequence.Thunk.iterator(i)]):(s=function(){return n.Sequence.Thunk.iterator(i)()},t())})})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/union",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.union=function(e,t,r){return new n.Sequence(function(i,u){var o=void 0===i?[function(){return e.iterate()},function(){return t.iterate()}]:i,c=o[0],s=o[1];return n.Sequence.Iterator.when(c(),function(){return n.Sequence.Iterator.when(s(),function(){return u()},function(e){return u(n.Sequence.Thunk.value(e),[n.Sequence.Iterator.done,n.Sequence.Thunk.iterator(e)])})},function(e){return n.Sequence.Iterator.when(s(),function(){return u(n.Sequence.Thunk.value(e),[n.Sequence.Thunk.iterator(e),n.Sequence.Iterator.done])},function(t){var i=r(n.Sequence.Thunk.value(e),n.Sequence.Thunk.value(t));return i<0?u(n.Sequence.Thunk.value(e),[n.Sequence.Thunk.iterator(e),function(){return t}]):i>0?u(n.Sequence.Thunk.value(t),[function(){return e},n.Sequence.Thunk.iterator(t)]):u(n.Sequence.Thunk.value(e),[n.Sequence.Thunk.iterator(e),n.Sequence.Thunk.iterator(t)])})})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/intersect",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.intersect=function(e,t,r){return new n.Sequence(function(i,u){var o=void 0===i?[function(){return e.iterate()},function(){return t.iterate()}]:i,c=o[0],s=o[1];return n.Sequence.Iterator.when(c(),function(){return u()},function(e,t){return n.Sequence.Iterator.when(s(),function(){return u()},function(i,o){var c=r(n.Sequence.Thunk.value(e),n.Sequence.Thunk.value(i));return c<0?(s=function(){return i},t()):c>0?o():u(n.Sequence.Thunk.value(e),[n.Sequence.Thunk.iterator(e),n.Sequence.Thunk.iterator(i)])})})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/pure",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.pure=function(e){return new n.Sequence(function(t,n){return n(e)})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/return",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.Return=function(e){return new n.Sequence(function(t,n){return n(e)})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/mempty",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r,r.mempty=new n.Sequence(function(e,t){return t()})}),define("src/lib/monad/sequence/member/static/mconcat",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";function r(e,t){return new n.Sequence(function(r,i){var u=void 0===r?[function(){return e.iterate()},function(){return t.iterate()}]:r,o=u[0],c=u[1];return n.Sequence.Iterator.when(o(),function(){return n.Sequence.Iterator.when(c(),function(){return i()},function(e){return i(n.Sequence.Thunk.value(e),[n.Sequence.Iterator.done,n.Sequence.Thunk.iterator(e)])})},function(e){return i(n.Sequence.Thunk.value(e),[n.Sequence.Thunk.iterator(e),c])})})}var i=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.mconcat=function(e){return Array.from(e).reduce(function(e,t){return r(e,t)},n.Sequence.mempty)},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=i}),define("src/lib/monad/sequence/member/static/mappend",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.mappend=function(e,t){return n.Sequence.mconcat([e,t])},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/static/mzero",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r,r.mzero=n.Sequence.mempty}),define("src/lib/monad/sequence/member/static/mplus",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r,r.mplus=n.Sequence.mappend}),define("src/lib/monad/sequence/member/instance/extract",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.extract=function(){for(var e=this,t=[],i=function(){return e.iterate()};;){var u=i();if(!n.Sequence.isIterable(u))return t;void r.concat(t,[n.Sequence.Thunk.value(u)]),i=n.Sequence.Thunk.iterator(u)}},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=i}),define("src/lib/monad/sequence/member/instance/iterate",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.iterate=function(){return this.iterate_()},t.prototype.iterate_=function(e,t){var r=this;void 0===t&&(t=0);var i=this.cons(e,n.Sequence.Data.cons);switch(i.length){case 0:return[void 0,n.Sequence.Iterator.done,-1];case 1:return[i[0],function(){return n.Sequence.Iterator.done()},t];case 2:return[i[0],function(){return r.iterate_(i[1],t+1)},t];default:throw n.Sequence.Exception.invalidDataError(i)}},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/memoize",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=new WeakMap,i=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.memoize=function(){var e=this;return new n.Sequence(function(t,i){var u=void 0===t?[0,r.get(e)||r.set(e,new Map).get(e)]:t,o=u[0],c=u[1];return n.Sequence.Iterator.when(c.get(o)||c.set(o,o>0&&c.has(o-1)?n.Sequence.Thunk.iterator(c.get(o-1))():e.iterate()).get(o),function(){return i()},function(e){return i(n.Sequence.Thunk.value(e),[o+1,c])})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=i}),define("src/lib/monad/sequence/member/instance/reduce",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.reduce=function(){var e=this;return new n.Sequence(function(t,r){var i=void 0===t?[0,new Map]:t,u=i[0],o=i[1];return n.Sequence.Iterator.when(o.get(u)||o.set(u,u>0&&o.has(u-1)?n.Sequence.Thunk.iterator(o.get(u-1))():e.iterate()).get(u),function(){return r()},function(e){return r(n.Sequence.Thunk.value(e),[u+1,o])})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/take",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.take=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(e>0?r():n.Sequence.Iterator.done(),function(){return i()},function(t){return n.Sequence.Thunk.index(t)+1<e?i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t)):i(n.Sequence.Thunk.value(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/drop",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.drop=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){ | ||
return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return n.Sequence.Thunk.index(t)<e?r():i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/takeWhile",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.takeWhile=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t){return e(n.Sequence.Thunk.value(t))?i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t)):i()})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/dropWhile",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.dropWhile=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return e(n.Sequence.Thunk.value(t))?r():i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/takeUntil",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.takeUntil=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t){return e(n.Sequence.Thunk.value(t))?i(n.Sequence.Thunk.value(t)):i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/dropUntil",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.dropUntil=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return e(n.Sequence.Thunk.value(t))?r():i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/fmap",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.fmap=function(e){var t=this;return new n.Sequence(function(r){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return n.Sequence.Data.cons()},function(t){return n.Sequence.Data.cons(e(n.Sequence.Thunk.value(t)),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/ap",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.ap=function(e){return n.Sequence.ap(this,e)},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/bind",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.bind=function(e){return n.Sequence.concat(this.fmap(e))},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/mapM",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.mapM=function(e){var t=this;return n.Sequence.from([0]).bind(function(){var i=t.extract();switch(i.length){case 0:return n.Sequence.mempty;default:var u=i.shift();return e(u).bind(function(t){return 0===i.length?n.Sequence.from([[t]]):n.Sequence.from(i).mapM(e).fmap(function(e){return r.concat([t],e)})})}})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=i}),define("src/lib/monad/sequence/member/instance/filterM",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.filterM=function(e){var t=this;return n.Sequence.from([0]).bind(function(){var i=t.extract();switch(i.length){case 0:return n.Sequence.from([[]]);default:var u=i.shift();return e(u).bind(function(t){return t?0===i.length?n.Sequence.from([[u]]):n.Sequence.from(i).filterM(e).fmap(function(e){return r.concat([u],e)}):0===i.length?n.Sequence.from([[]]):n.Sequence.from(i).filterM(e)})}})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=i}),define("src/lib/monad/sequence/member/instance/map",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.map=function(e){var t=this;return new n.Sequence(function(r){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return n.Sequence.Data.cons()},function(t){return n.Sequence.Data.cons(e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.index(t)),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/filter",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.filter=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.index(t))?i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t)):r()})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/scan",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.scan=function(e,t){var r=this;return new n.Sequence(function(i){var u=void 0===i?[t,function(){return r.iterate()},0]:i,o=u[0],c=u[1],s=u[2];return n.Sequence.Iterator.when(c(),function(){return 0===s?n.Sequence.Data.cons(t):n.Sequence.Data.cons()},function(t){return n.Sequence.Data.cons(o=e(o,n.Sequence.Thunk.value(t)),[o,n.Sequence.Thunk.iterator(t),n.Sequence.Thunk.index(t)+1])})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/fold",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.fold=function(e,t){var r=this;return new n.Sequence(function(i){return void 0===i&&(i=function(){return r.reduce().iterate()}),n.Sequence.Iterator.when(i(),function(){return n.Sequence.Data.cons(t)},function(r){return n.Sequence.Data.cons(e(n.Sequence.Thunk.value(r),n.Sequence.resume(n.Sequence.Thunk.iterator(r)).fold(e,t)))})}).bind(function(e){return e})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=r}),define("src/lib/monad/sequence/member/instance/group",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.group=function(e){var t=this;return new n.Sequence(function(i,u){var o=void 0===i?[function(){return t.iterate()},[]]:i,c=o[0],s=o[1];return n.Sequence.Iterator.when(c(),function(){return 0===s.length?u():u(s)},function(t,i){return 0===s.length||e(s[0],n.Sequence.Thunk.value(t))?(r.concat(s,[n.Sequence.Thunk.value(t)]),i()):u(s,[n.Sequence.Thunk.iterator(t),r.concat([],[n.Sequence.Thunk.value(t)])])})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=i}),define("src/lib/monad/sequence/member/instance/subsequences",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";function i(e){return n.Sequence.Iterator.when(e.iterate(),function(){return n.Sequence.mempty},function(e){return n.Sequence.mappend(n.Sequence.from([[n.Sequence.Thunk.value(e)]]),new n.Sequence(function(t,u){return n.Sequence.Iterator.when(e,function(){return u()},function(e){return u(i(n.Sequence.resume(n.Sequence.Thunk.iterator(e))).fold(function(t,i){return n.Sequence.mappend(n.Sequence.mappend(n.Sequence.from([t]),n.Sequence.from([r.concat([n.Sequence.Thunk.value(e)],t)])),i)},n.Sequence.mempty))})}).bind(function(e){return e}))})}var u=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.subsequences=function(){var e=this;return n.Sequence.mappend(n.Sequence.from([[]]),n.Sequence.from([0]).bind(function(){return i(e)}))},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=u}),define("src/lib/monad/sequence/member/instance/permutations",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";function r(e,t){return n.Sequence.Iterator.when(e.iterate(),function(){return n.Sequence.mempty},function(e){return new n.Sequence(function(i,u){return n.Sequence.Iterator.when(e,function(){return u()},function(e){function i(e,t){return o(function(e){return e},e,t)[1]}function o(e,t,r){return n.Sequence.Iterator.when(t.iterate(),function(){return[s,r]},function(t){var i=n.Sequence.Thunk.value(t),u=o(function(t){return e(n.Sequence.mappend(n.Sequence.from([i]),t))},n.Sequence.resume(n.Sequence.Thunk.iterator(t)),r),s=u[0],a=u[1];return[n.Sequence.mappend(n.Sequence.from([i]),s),n.Sequence.mappend(n.Sequence.from([e(n.Sequence.mappend(n.Sequence.from([c]),n.Sequence.mappend(n.Sequence.from([i]),s))).extract()]),a)]})}var c=n.Sequence.Thunk.value(e),s=n.Sequence.resume(n.Sequence.Thunk.iterator(e)).memoize();return u(t.permutations().fold(function(e,t){return i(n.Sequence.from(e),t)},r(s,n.Sequence.mappend(n.Sequence.from([c]),t))))})}).bind(function(e){return e})})}var i=function(e){function t(){return e.apply(this,arguments)||this}return __extends(t,e),t.prototype.permutations=function(){var e=this;return n.Sequence.from([0]).bind(function(){var t=e.extract();return 0===t.length?n.Sequence.mempty:n.Sequence.from([t])}).bind(function(e){return n.Sequence.mappend(n.Sequence.from([e]),r(n.Sequence.from(e),n.Sequence.mempty))})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t.default=i}),define("src/lib/type",["require","exports"],function(e,t){"use strict";function n(e){return Object.prototype.toString.call(e).split(" ").pop().slice(0,-1)}t.type=n}),define("src/lib/assign",["require","exports","src/lib/type"],function(e,t,n){"use strict";function r(e){return function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(void 0===t||null===t)throw new TypeError("Spica: assign: Cannot walk on "+t+".");for(var i=0,u=n;i<u.length;i++){var o=u[i];if(void 0!==o&&null!==o)for(var c=0,s=Object.keys(Object(o));c<s.length;c++){var a=s[c],f=Object.getOwnPropertyDescriptor(Object(o),a);void 0!==f&&f.enumerable&&void e(a,Object(t),Object(o))}}return Object(t)}}t.assign=r(function(e,t,n){return t[e]=n[e]}),t.clone=r(function(e,r,i){switch(n.type(i[e])){case"Array":return r[e]=t.clone([],i[e]);case"Object":return r[e]=t.clone({},i[e]);default:return r[e]=i[e]}}),t.extend=r(function(e,r,i){switch(n.type(i[e])){case"Array":return r[e]=t.extend([],i[e]);case"Object":switch(n.type(r[e])){case"Function":case"Object":return r[e]=t.extend(r[e],i[e]);default:return r[e]=t.extend({},i[e])}default:return r[e]=i[e]}})}),define("src/lib/compose",["require","exports","src/lib/assign"],function(e,t,n){"use strict";function r(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return t.reduce(function(e,t){void n.assign(e.prototype,t.prototype);for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e},e)}t.compose=r}),define("src/lib/monad/sequence",["require","exports","src/lib/monad/sequence/core","src/lib/monad/sequence/member/static/resume","src/lib/monad/sequence/member/static/from","src/lib/monad/sequence/member/static/cycle","src/lib/monad/sequence/member/static/random","src/lib/monad/sequence/member/static/concat","src/lib/monad/sequence/member/static/zip","src/lib/monad/sequence/member/static/difference","src/lib/monad/sequence/member/static/union","src/lib/monad/sequence/member/static/intersect","src/lib/monad/sequence/member/static/pure","src/lib/monad/sequence/member/static/return","src/lib/monad/sequence/member/static/mempty","src/lib/monad/sequence/member/static/mconcat","src/lib/monad/sequence/member/static/mappend","src/lib/monad/sequence/member/static/mzero","src/lib/monad/sequence/member/static/mplus","src/lib/monad/sequence/member/instance/extract","src/lib/monad/sequence/member/instance/iterate","src/lib/monad/sequence/member/instance/memoize","src/lib/monad/sequence/member/instance/reduce","src/lib/monad/sequence/member/instance/take","src/lib/monad/sequence/member/instance/drop","src/lib/monad/sequence/member/instance/takeWhile","src/lib/monad/sequence/member/instance/dropWhile","src/lib/monad/sequence/member/instance/takeUntil","src/lib/monad/sequence/member/instance/dropUntil","src/lib/monad/sequence/member/instance/fmap","src/lib/monad/sequence/member/instance/ap","src/lib/monad/sequence/member/instance/bind","src/lib/monad/sequence/member/instance/mapM","src/lib/monad/sequence/member/instance/filterM","src/lib/monad/sequence/member/instance/map","src/lib/monad/sequence/member/instance/filter","src/lib/monad/sequence/member/instance/scan","src/lib/monad/sequence/member/instance/fold","src/lib/monad/sequence/member/instance/group","src/lib/monad/sequence/member/instance/subsequences","src/lib/monad/sequence/member/instance/permutations","src/lib/compose"],function(e,t,n,r,i,u,o,c,s,a,f,d,l,p,h,v,m,q,b,y,S,x,_,w,k,g,T,M,I,O,j,E,P,N,A,R,D,z,C,L,F,W){"use strict";t.Sequence=n.Sequence,void W.compose(n.Sequence,r.default,i.default,u.default,o.default,c.default,s.default,a.default,f.default,d.default,l.default,p.default,h.default,v.default,m.default,q.default,b.default,y.default,S.default,x.default,_.default,w.default,k.default,g.default,T.default,M.default,I.default,O.default,j.default,E.default,P.default,N.default,A.default,R.default,D.default,z.default,C.default,L.default,F.default)}),define("src/lib/flip",["require","exports","src/lib/curry"],function(e,t,n){"use strict";function r(e){return n.curry(function(t,n){return e.length>1?e(n,t):e(n)(t)})}t.flip=r}),define("src/lib/list",["require","exports","src/lib/concat"],function(e,t,n){"use strict";var r=function(){function e(){void this.NIL}return e.prototype.push=function(e){return new i(e,this)},e.prototype.array=function(){return[]},e}();t.Nil=r;var i=function(){function e(e,t){this.head_=e,this.tail_=t,void this.CONS}return e.prototype.push=function(t){return new e(t,this)},e.prototype.head=function(){return this.head_},e.prototype.tail=function(){return this.tail_},e.prototype.walk=function(e){return void e(this.head()),this.tail()},e.prototype.modify=function(e){return this.tail().push(e(this.head()))},e.prototype.extend=function(e){return this.push(e(this.head()))},e.prototype.compact=function(e){var t=this;return this.tail().modify(function(n){return e(t.head(),n)})},e.prototype.reverse=function(){return this.array().reduce(function(e,t){return e.push(t)},new r)},e.prototype.tuple=function(){return this.array()},e.prototype.array=function(){return n.concat([this.head()],this.tail().array())},e}()}),define("src/lib/hlist",["require","exports","src/lib/concat"],function(e,t,n){"use strict";var r=function(){function e(){void this.NIL}return e.prototype.push=function(e){return new i(e,this)},e.prototype.array=function(){return[]},e}();t.HNil=r;var i=function(){function e(e,t){this.head_=e,this.tail_=t,void this.CONS}return e.prototype.push=function(t){return new e(t,this)},e.prototype.head=function(){return this.head_},e.prototype.tail=function(){return this.tail_},e.prototype.walk=function(e){return void e(this.head()),this.tail()},e.prototype.modify=function(e){return this.tail().push(e(this.head()))},e.prototype.extend=function(e){return this.push(e(this.head()))},e.prototype.compact=function(e){var t=this;return this.tail().modify(function(n){return e(t.head(),n)})},e.prototype.reverse=function(){return this.array().reduce(function(e,t){return e.push(t)},new r)},e.prototype.tuple=function(){return this.array()},e.prototype.array=function(){return n.concat([this.head()],this.tail().array())},e}()}),define("src/lib/collection/datamap",["require","exports","src/lib/sqid","src/lib/type"],function(e,t,n,r){"use strict";function i(e){return e instanceof Object==!1}var u=function(){function e(e){void 0===e&&(e=[]);var t=this;this.store=new Map,this.weakstore=new WeakMap,void Array.from(e).forEach(function(e){var n=e[0],r=e[1];return void t.set(n,r)})}return e.prototype.stringify=function(e){switch(typeof e){case"undefined":return"0:"+e;case"boolean":return"1:"+e;case"number":return"2:"+(1e3+(""+e).length)+":"+e;case"string":return"3:"+(1e14+e.length)+":"+e;default:return i(e)?"8:"+e:Array.isArray(e)?"9:[ "+this.stringifyArray(e)+" ]":"9:{ "+(this.stringifyObject(e)||this.weakstore.get(e)||this.weakstore.set(e,n.sqid()).get(e))+" }"}},e.prototype.stringifyArray=function(e){for(var t="",n=0,r=e;n<r.length;n++){var i=r[n];t+=""+this.stringify(i)}return t},e.prototype.stringifyObject=function(e){if("Object"!==r.type(e))return"";for(var t=Object.keys(e),n="",i=0,u=t;i<u.length;i++){var o=u[i];n+=this.stringify(o)+": "+this.stringify(e[o])}return n||" "},e.prototype.get=function(e){return(this.store.get(this.stringify(e))||[])[1]},e.prototype.set=function(e,t){return void this.store.set(this.stringify(e),[e,t]),this},e.prototype.has=function(e){return this.store.has(this.stringify(e))},e.prototype.delete=function(e){return this.store.delete(this.stringify(e))},e.prototype.clear=function(){return this.store.clear()},Object.defineProperty(e.prototype,"size",{get:function(){return this.store.size},enumerable:!0,configurable:!0}),e}();t.DataMap=u}),define("src/lib/collection/cachemap",["require","exports"],function(e,t){"use strict";var n=Date.now();void setInterval(function(){return n=Date.now()},100);var r=function(){function e(e){void 0===e&&(e=[]);var t=this;this.store=new Map,void Array.from(e).forEach(function(e){var n=e[0],r=e[1];return void t.set(n,r)})}return e.prototype.clean=function(e){this.store.has(e)&&this.store.get(e)[0]<n&&void this.store.delete(e)},e.prototype.get=function(e){return void this.clean(e),(this.store.get(e)||[0,void 0])[1]},e.prototype.set=function(e,t,r){return void 0===r&&(r=1/0),void this.clean(e),void this.store.set(e,[n+r,t]),this},e.prototype.has=function(e){return void this.clean(e),this.store.has(e)},e.prototype.delete=function(e){return void this.clean(e),this.store.delete(e)},e.prototype.clear=function(){return this.store.clear()},Object.defineProperty(e.prototype,"size",{get:function(){return this.store.size},enumerable:!0,configurable:!0}),e}();t.CacheMap=r}),define("src/lib/collection/attrmap",["require","exports"],function(e,t){"use strict";var n=function(){function e(e,t,n){void 0===e&&(e=[]),void 0===t&&(t=WeakMap),void 0===n&&(n=Map);var r=this;this.KeyMap=t,this.ValueMap=n,this.store=new this.KeyMap,void Array.from(e).forEach(function(e){var t=e[0],n=e[1],i=e[2];return void r.set(t,n,i)})}return e.prototype.get=function(e,t){return this.store.get(e)&&this.store.get(e).get(t)},e.prototype.set=function(e,t,n){var r=this.store.has(e)?this.store.get(e):this.store.set(e,new this.ValueMap).get(e);return void r.set(t,n),this},e.prototype.has=function(e,t){return 1===arguments.length?this.store.has(e):this.store.has(e)&&this.store.get(e).has(t)},e.prototype.delete=function(e,t){return 1===arguments.length?this.store.delete(e):!!this.store.has(e)&&this.store.get(e).delete(t)},e}();t.AttrMap=n}),define("src/lib/mixin",["require","exports","src/lib/assign"],function(e,t,n){"use strict";function r(){for(var e=[],t=0;t<arguments.length;t++)e[t-0]=arguments[t];return e.reduceRight(function(e,t){return i(t,e)},function(){function e(){}return e}())}function i(e,t){var r=function(){function n(){return e.call(t.call(this)||this)}return n}();void n.assign(r.prototype,e.prototype,t.prototype);for(var i in t)t.hasOwnProperty(i)&&(r[i]=t[i]);for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);return r}t.Mixin=r}),define("src/lib/fingerprint",["require","exports"],function(e,t){"use strict";function n(){return i(u([o(window.navigator),o(window.screen),o((new Date).getTimezoneOffset())].join()))}function r(){return i(u([o(process)].join()))}function i(e){return e.split("").reduce(function(e,t,n){return(+t*n+e)%1e9||e-+t},0)}function u(e){return e.split("").map(function(e){return e.charCodeAt(0)}).join("")}function o(e,t){if(void 0===t&&(t=5),t>0&&e&&"object"==typeof e){var n="{";for(var r in e)n+='"'+r+'": '+o(e[r],t-1)+",";return n+="}"}return!e||e.toString?'"'+e+'"':'"'+Object.prototype.toString.call(e)+'"'}t.FINGERPRINT="object"==typeof window?n():r(),t.browser=n,t.server=r,t.hash=i,t.str2digit=u,t.stringify=o}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(e,t,n){"use strict";function r(){var e=o=o*Date.now()%1e15;if(e<16||1e15<e)throw new Error("Spica: uuid: Invalid uuid dynamic seed.");for(var t="",n=0,r=u;n<r.length;n++){var i=r[n];if("x"===i||"y"===i){var c=Math.random()*e%16|0,s="x"==i?c:3&c|8;t+=s.toString(16)}else t+=i}return t.toLowerCase()}var i=n.FINGERPRINT*Date.now()%1e15;if(!i||"number"!=typeof i||i<100||1e15<i)throw new Error("Spica: uuid: Invalid uuid static seed.\n\t"+n.FINGERPRINT);var u=Object.freeze("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split("")),o=i;t.v4=r}),define("src/lib/sort",["require","exports"],function(e,t){"use strict";function n(e,t,n,r){if(void 0===r&&(r=!1),!r&&n*n>1.25*e.length)return e.sort(t);n=n<e.length-1?n:e.length-1;for(var i=0;i<n;++i)for(var u=i+1;u<e.length;++u)if(t(e[i],e[u])>0!=!1){var o=e[i];e[i]=e[u],e[u]=o}return e}t.sort=n}),define("src/export",["require","exports","src/lib/supervisor","src/lib/observable","src/lib/cancelable","src/lib/monad/sequence","src/lib/monad/maybe","src/lib/monad/either","src/lib/curry","src/lib/flip","src/lib/list","src/lib/hlist","src/lib/collection/datamap","src/lib/collection/cachemap","src/lib/collection/attrmap","src/lib/mixin","src/lib/tick","src/lib/fingerprint","src/lib/uuid","src/lib/sqid","src/lib/assign","src/lib/concat","src/lib/sort"],function(e,t,n,r,i,u,o,c,s,a,f,d,l,p,h,v,m,q,b,y,S,x,_){"use strict";t.Supervisor=n.Supervisor,t.Observable=r.Observable,t.Cancelable=i.Cancelable,t.Sequence=u.Sequence,t.Maybe=o.Maybe,t.Just=o.Just,t.Nothing=o.Nothing,t.Either=c.Either,t.Left=c.Left,t.Right=c.Right,t.curry=s.curry,t.flip=a.flip,t.Nil=f.Nil,t.HNil=d.HNil,t.DataMap=l.DataMap,t.CacheMap=p.CacheMap,t.AttrMap=h.AttrMap,t.Mixin=v.Mixin,t.Tick=m.Tick,t.FINGERPRINT=q.FINGERPRINT,t.uuid=b.v4,t.sqid=y.sqid,t.assign=S.assign,t.clone=S.clone,t.extend=S.extend,t.concat=x.concat,t.sort=_.sort}),define("spica",["require","exports","src/export","./src/import"],function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}r(n)}); |
{ | ||
"name": "spica", | ||
"version": "0.0.32", | ||
"version": "0.0.33", | ||
"description": "Supervisor, Observable, Sequence, Maybe, Either and some utils.", | ||
@@ -37,5 +37,5 @@ "private": false, | ||
"devDependencies": { | ||
"@types/benchmark": "^1.0.29", | ||
"@types/mocha": "^2.2.31", | ||
"@types/power-assert": "0.0.27", | ||
"@types/benchmark": "^1.0.30", | ||
"@types/mocha": "^2.2.32", | ||
"@types/power-assert": "1.4.29", | ||
"benchmark": "^2.1.1", | ||
@@ -49,3 +49,3 @@ "del": "^2.2.2", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-typescript": "2.13.6", | ||
"gulp-typescript": "3.0.2", | ||
"gulp-uglify": "^2.0.0", | ||
@@ -59,9 +59,9 @@ "gulp-unassert": "^1.0.0", | ||
"karma-firefox-launcher": "^1.0.0", | ||
"karma-mocha": "^1.1.1", | ||
"lodash": "^4.15.0", | ||
"mocha": "^3.0.2", | ||
"npm-check-updates": "^2.8.0", | ||
"karma-mocha": "^1.2.0", | ||
"lodash": "^4.16.2", | ||
"mocha": "^3.1.0", | ||
"npm-check-updates": "^2.8.1", | ||
"power-assert": "^1.4.1", | ||
"run-sequence": "^1.2.2", | ||
"typescript": "2.1.0-dev.20160903" | ||
"typescript": "2.1.0-dev.20161003" | ||
}, | ||
@@ -68,0 +68,0 @@ "scripts": { |
@@ -30,2 +30,3 @@ # Spica | ||
- DataMap | ||
- CacheMap | ||
- AttrMap | ||
@@ -32,0 +33,0 @@ - Mixin |
@@ -9,35 +9,42 @@ /** | ||
declare module 'spica' { | ||
export namespace Supervisor { | ||
export namespace Event { | ||
export namespace Data { | ||
export type Exec<T extends string[], D, R> = [T, (data: D) => R]; | ||
export type Fail<T extends string[], D> = [T, D]; | ||
export type Loss<T extends string[], D> = [T, D]; | ||
export type Exit<T extends string[], D, R> = [T, (data: D) => R, any]; | ||
} | ||
} | ||
} | ||
export abstract class Supervisor<T extends string[], D, R> { | ||
export abstract class Supervisor<N extends string, P, R, S> { | ||
static readonly count: number; | ||
static readonly procs: number; | ||
constructor(settings?: SupervisorSettings<T>) | ||
constructor(settings?: Supervisor.Settings<N>) | ||
readonly id: string; | ||
readonly name: string; | ||
readonly events: { | ||
readonly exec: Observer<T, Supervisor.Event.Data.Exec<T, D, R>, any>; | ||
readonly fail: Observer<T, Supervisor.Event.Data.Fail<T, D>, any>; | ||
readonly loss: Observer<T, Supervisor.Event.Data.Loss<T, D>, any>; | ||
readonly exit: Observer<T, Supervisor.Event.Data.Exit<T, D, R>, any>; | ||
readonly init: Observer<never[] | [N], Supervisor.Event.Data.Init<N, P, R, S>, any>; | ||
readonly loss: Observer<never[] | [N], Supervisor.Event.Data.Loss<N, P>, any>; | ||
readonly exit: Observer<never[] | [N], Supervisor.Event.Data.Exit<N, P, R, S>, any>; | ||
}; | ||
register(namespace: T, process: (data: D) => R): (reason?: any) => void; | ||
call(namespace: T, data: D, timeout?: number): Promise<R[]>; | ||
cast(namespace: T, data: D, retry?: boolean): R[]; | ||
refs(namespace: T): [T, (data: D) => R, (reason: any) => void][]; | ||
terminate(namespace?: T, reason?: any): void; | ||
register(name: N, process: Supervisor.Process<P, R, S> | Supervisor.Process.Call<P, R, S>, state: S): (reason?: any) => void; | ||
call(name: N, param: P, callback: (reply: R, error?: Error) => void, timeout?: number): void; | ||
cast(name: N, param: P, timeout?: number): boolean; | ||
refs(name?: N): [N, Supervisor.Process<P, R, S>, S, (reason: any) => void][]; | ||
terminate(name?: N, reason?: any): void; | ||
} | ||
export interface SupervisorSettings<T> { | ||
readonly name?: string; | ||
readonly dependencies?: [T, T[]][]; | ||
readonly retry?: boolean; | ||
readonly timeout?: number; | ||
readonly destructor?: (reason?: any) => any; | ||
export namespace Supervisor { | ||
export interface Settings<N extends string> { | ||
readonly name?: string; | ||
readonly timeout?: number; | ||
readonly destructor?: (reason: any) => any; | ||
} | ||
export interface Process<P, R, S> { | ||
readonly init: Process.Init<S>; | ||
readonly call: Process.Call<P, R, S>; | ||
readonly exit: Process.Exit<S>; | ||
} | ||
export namespace Process { | ||
export type Init<S> = (state: S) => S; | ||
export type Call<P, R, S> = (param: P, state: S) => [R, S] | PromiseLike<[R, S]>; | ||
export type Exit<S> = (state: S, reason: any) => void; | ||
} | ||
export namespace Event { | ||
export namespace Data { | ||
export type Init<N extends string, P, R, S> = [N, Process<P, R, S>, S]; | ||
export type Loss<N extends string, P> = [N, P]; | ||
export type Exit<N extends string, P, R, S> = [N, Process<P, R, S>, S, any]; | ||
} | ||
} | ||
} | ||
@@ -413,2 +420,11 @@ | ||
} | ||
export class CacheMap<K, V> implements WeakMapLike<K, V> { | ||
constructor(entries?: Iterable<[K, V]>); | ||
get(key: K): V | undefined; | ||
set(key: K, val: V, expiry?: number): this; | ||
has(key: K): boolean; | ||
delete(key: K): boolean; | ||
clear(): void; | ||
size: number; | ||
} | ||
export class AttrMap<C, K, V> { | ||
@@ -415,0 +431,0 @@ constructor( |
@@ -12,2 +12,3 @@ export {Supervisor} from './lib/supervisor'; | ||
export {DataMap} from './lib/collection/datamap'; | ||
export {CacheMap} from './lib/collection/cachemap'; | ||
export {AttrMap} from './lib/collection/attrmap'; | ||
@@ -14,0 +15,0 @@ export {Mixin} from './lib/mixin'; |
@@ -6,3 +6,3 @@ import {type} from './type'; | ||
export let clone = template((key, target, source): any => { | ||
export const clone = template((key, target, source): any => { | ||
switch (type(source[key])) { | ||
@@ -18,3 +18,3 @@ case 'Array': | ||
export let extend = template((key, target, source): any => { | ||
export const extend = template((key, target, source): any => { | ||
switch (type(source[key])) { | ||
@@ -51,3 +51,3 @@ case 'Array': | ||
for (const key of Object.keys(Object(source))) { | ||
let desc = Object.getOwnPropertyDescriptor(Object(source), key); | ||
const desc = Object.getOwnPropertyDescriptor(Object(source), key); | ||
if (desc !== undefined && desc.enumerable) { | ||
@@ -54,0 +54,0 @@ void cb(key, Object(target), Object(source)); |
@@ -110,3 +110,3 @@ import {Sequence as ISequence} from 'spica'; | ||
export namespace Iterator { | ||
export let /* const */ done: Sequence.Iterator<any> = () => <Sequence.Thunk<any>>[void 0, done, -1]; | ||
export const done: Sequence.Iterator<any> = () => <Sequence.Thunk<any>>[void 0, done, -1]; | ||
export function when<a, b>( | ||
@@ -113,0 +113,0 @@ thunk: Thunk<a>, |
@@ -175,5 +175,5 @@ import {Observer, Publisher} from 'spica'; | ||
default: | ||
throw new TypeError(`Spica: Observable: Invalid subscriber.\n\t${types, subscriber}`); | ||
throw new TypeError(`Spica: Observable: Invalid subscriber.\n\t${types} ${subscriber}`); | ||
} | ||
} | ||
} |
@@ -17,3 +17,3 @@ import {Supervisor} from './supervisor'; | ||
it('extend', function (done) { | ||
class TestSupervisor extends Supervisor<string[], number, number> { | ||
class TestSupervisor extends Supervisor<string, number, number, number> { | ||
} | ||
@@ -32,3 +32,3 @@ | ||
const sv2 = new class TestSupervisor extends Supervisor<string[], number, number> { }(); | ||
const sv2 = new class TestSupervisor extends Supervisor<string, number, number, number> { }(); | ||
assert(Supervisor.count === 0); | ||
@@ -39,8 +39,10 @@ assert(Supervisor.procs === 0); | ||
function id<T>(a: T): T { | ||
return a; | ||
} | ||
const terminate = sv1.register([], id); | ||
assert.deepStrictEqual(sv1.refs([]), [ | ||
[[], id, terminate] | ||
const process: Supervisor.Process<number, number, number> = { | ||
init: (state) => state, | ||
call: (n, s) => [n, ++s], | ||
exit: () => void 0 | ||
}; | ||
const terminate = sv1.register('', process, 0); | ||
assert.deepStrictEqual(sv1.refs(), [ | ||
['', process, 0, terminate] | ||
]); | ||
@@ -51,3 +53,3 @@ assert(Supervisor.count === 0); | ||
assert(TestSupervisor.procs === 1); | ||
sv1.terminate([]); | ||
sv1.terminate(''); | ||
assert(Supervisor.count === 0); | ||
@@ -71,3 +73,3 @@ assert(Supervisor.procs === 0); | ||
it('refs', function (done) { | ||
class TestSupervisor extends Supervisor<string[], number, number> { | ||
class TestSupervisor extends Supervisor<string, number, number, number> { | ||
} | ||
@@ -79,12 +81,14 @@ assert(TestSupervisor.count === 0); | ||
assert(TestSupervisor.procs === 0); | ||
function id<T>(a: T): T { | ||
return a; | ||
} | ||
const terminate = sv.register([], id); | ||
assert.deepStrictEqual(sv.refs([]), [ | ||
[[], id, terminate] | ||
const process: Supervisor.Process<number, number, number> = { | ||
init: (state) => state, | ||
call: (n, s) => [n, ++s], | ||
exit: () => void 0 | ||
}; | ||
const terminate = sv.register('', process, 0); | ||
assert.deepStrictEqual(sv.refs(), [ | ||
['', process, 0, terminate] | ||
]); | ||
assert(TestSupervisor.count === 1); | ||
assert(TestSupervisor.procs === 1); | ||
sv.terminate([]); | ||
sv.terminate(''); | ||
assert(TestSupervisor.count === 1); | ||
@@ -99,4 +103,4 @@ assert(TestSupervisor.procs === 0); | ||
it('lifecycle', function (done) { | ||
let cnt = 0; | ||
class TestSupervisor extends Supervisor<string[], number, number> { | ||
let cnt = 1; | ||
class TestSupervisor extends Supervisor<string, number, number, number> { | ||
} | ||
@@ -106,10 +110,10 @@ assert(TestSupervisor.count === 0); | ||
const sv = new TestSupervisor({ | ||
name: void 0, | ||
name: '', | ||
destructor: reason => { | ||
assert(reason === void 0); | ||
assert(++cnt === 13); | ||
assert(cnt === 12 && ++cnt); | ||
assert(TestSupervisor.count === 1); | ||
assert(TestSupervisor.procs === 0); | ||
Tick(() => { | ||
assert(++cnt === 14); | ||
assert(cnt === 13 && ++cnt); | ||
assert(TestSupervisor.count === 0); | ||
@@ -121,44 +125,32 @@ assert(TestSupervisor.procs === 0); | ||
}); | ||
assert(+sv.id > 0); | ||
assert(sv.name === ''); | ||
sv.events.exec | ||
.monitor([], ([name, process]) => { | ||
assert.deepStrictEqual(name, []); | ||
assert(process instanceof Function); | ||
assert(++cnt === 1); | ||
sv.events.init | ||
.monitor([], ([name, process, state]) => { | ||
assert(TestSupervisor.procs === 1); | ||
assert(cnt === 2 && ++cnt); | ||
assert(name === ''); | ||
assert(process.init instanceof Function); | ||
assert(process.call instanceof Function); | ||
assert(process.exit instanceof Function); | ||
assert(state === 0); | ||
}); | ||
sv.events.fail | ||
.monitor([], ([name, data]) => { | ||
assert.deepStrictEqual(name, []); | ||
switch (data) { | ||
case 3: { | ||
assert(++cnt === 6); | ||
assert(data === 3); | ||
return; | ||
} | ||
case 4: { | ||
assert(++cnt === 8); | ||
assert(data === 4); | ||
return; | ||
} | ||
default: { | ||
throw new Error(data + ''); | ||
} | ||
} | ||
}); | ||
sv.events.loss | ||
.monitor([], ([name, data]) => { | ||
assert.deepStrictEqual(name, []); | ||
switch (data) { | ||
.monitor([], ([name, param]) => { | ||
assert(TestSupervisor.procs === 0); | ||
assert(name === ''); | ||
switch (param) { | ||
case 3: { | ||
assert(++cnt === 7); | ||
assert(data === 3); | ||
assert(cnt === 10 && ++cnt); | ||
assert(param === 3); | ||
return; | ||
} | ||
case 4: { | ||
assert(++cnt === 9); | ||
assert(data === 4); | ||
assert(cnt === 11 && ++cnt); | ||
assert(param === 4); | ||
sv.terminate(); | ||
return; | ||
} | ||
default: { | ||
throw new Error(data + ''); | ||
throw new Error(param + ''); | ||
} | ||
@@ -168,128 +160,81 @@ } | ||
sv.events.exit | ||
.monitor([], ([name, process, reason]) => { | ||
assert(++cnt === 5); | ||
assert.deepStrictEqual(name, []); | ||
assert(process instanceof Function); | ||
.monitor([], ([name, process, state, reason]) => { | ||
assert(TestSupervisor.procs === 0); | ||
assert(cnt === 9 && ++cnt); | ||
assert(name === ''); | ||
assert(process.init instanceof Function); | ||
assert(process.call instanceof Function); | ||
assert(process.exit instanceof Function); | ||
assert(state === 2); | ||
assert(reason instanceof Error); | ||
}); | ||
sv.register([], n => { | ||
if (n > 2) throw new Error(); | ||
++cnt; | ||
return -n; | ||
}); | ||
assert(cnt === 0); | ||
sv.call([], 1, 0).then(r => assert(++cnt === 10) || assert.deepStrictEqual(r, [-1])); | ||
assert.deepStrictEqual(sv.cast([], 2), [-2]); | ||
sv.call([], 3, 0).catch(_ => assert(++cnt === 11) || assert(TestSupervisor.procs === 0)); | ||
sv.call([], 4, 0).catch(_ => assert(++cnt === 12) || assert(TestSupervisor.procs === 0) || sv.terminate()); | ||
assert(++cnt === 3); | ||
sv.register('', { | ||
init(state) { | ||
assert(TestSupervisor.procs === 1); | ||
assert(cnt === 3 && ++cnt); | ||
assert(state === 0); | ||
return state; | ||
}, | ||
call(n: number, state: number): [number, number] { | ||
assert(TestSupervisor.procs === 1); | ||
if (n >= 3) throw new Error(); | ||
++cnt; // 4, 6 | ||
return [-n, ++state]; | ||
}, | ||
exit(state, reason) { | ||
assert(TestSupervisor.procs === 0); | ||
assert(cnt === 8 && ++cnt); | ||
assert(state === 2); | ||
assert(reason instanceof Error); | ||
} | ||
}, 0); | ||
assert(cnt === 1 && ++cnt); | ||
sv.call('', 1, r => assert(TestSupervisor.procs === 1) || assert(r === -1) || assert(cnt === 7 && ++cnt)); | ||
assert(sv.cast('', 2) === true); | ||
sv.call('', 3, done); | ||
sv.call('', 4, done); | ||
assert(cnt === 5 && ++cnt); | ||
}); | ||
it('dependencies', function (done) { | ||
let cnt = 0; | ||
class TestSupervisor extends Supervisor<string[], number, number> { | ||
} | ||
assert(TestSupervisor.count === 0); | ||
assert(TestSupervisor.procs === 0); | ||
const sv = new TestSupervisor({ | ||
name: 'deps', | ||
dependencies: [ | ||
[[], [ | ||
['a'], | ||
['b'] | ||
]], | ||
[['a'], [ | ||
[], | ||
['a', 'a'] | ||
]], | ||
[['a', 'a'], [ | ||
['a'] | ||
]], | ||
[['b'], [ | ||
[], | ||
['a'] | ||
]] | ||
] | ||
it('state', function (done) { | ||
const sv = new class TestSupervisor extends Supervisor<string, number, number, number> { }(); | ||
sv.register('', (n, s) => Promise.resolve<[number, number]>([n + s, ++s]), 0); | ||
sv.call('', 1, n => assert(n === 1)); | ||
sv.call('', 2, n => assert(n === 3) || sv.terminate() || done(), 1e2); | ||
}); | ||
it('timeout of messaging', function (done) { | ||
let cnt = 1; | ||
const sv = new class TestSupervisor extends Supervisor<string, number, number, number> { }(); | ||
sv.events.loss.once([''], ([, n]) => { | ||
assert(n === 2); | ||
assert(cnt === 1 && ++cnt); | ||
sv.events.loss.once([''], ([, n]) => { | ||
assert(n === 1); | ||
assert(cnt === 3 && ++cnt); | ||
done(); | ||
}); | ||
}); | ||
sv.events.loss.monitor([], done); | ||
sv.call('', 1, (r, e) => assert(r === void 0) || assert(e instanceof Error) || assert(cnt === 4 && ++cnt), 1e2); | ||
sv.call('', 2, (r, e) => assert(r === void 0) || assert(e instanceof Error) || assert(cnt === 2 && ++cnt)); | ||
}); | ||
sv.register([], _ => ++cnt); | ||
assert.deepStrictEqual(sv.cast([], 0), []); | ||
assert.deepStrictEqual(sv.cast(['a'], 0), []); | ||
assert.deepStrictEqual(sv.cast(['a', 'a'], 0), []); | ||
assert.deepStrictEqual(sv.cast(['b'], 0), []); | ||
assert(cnt === 0); | ||
sv.register(['a', 'a'], _ => ++cnt); | ||
assert.deepStrictEqual(sv.cast([], 0), []); | ||
assert.deepStrictEqual(sv.cast(['a'], 0), []); | ||
assert.deepStrictEqual(sv.cast(['a', 'a'], 0), []); | ||
assert.deepStrictEqual(sv.cast(['b'], 0), []); | ||
assert(cnt === 0); | ||
sv.register(['a'], _ => ++cnt); | ||
assert.deepStrictEqual(sv.cast([], 0), []); | ||
assert.deepStrictEqual(sv.cast(['a'], 0), []); | ||
assert.deepStrictEqual(sv.cast(['a', 'a'], 0), []); | ||
assert.deepStrictEqual(sv.cast(['b'], 0), []); | ||
assert(cnt === 0); | ||
sv.register(['b'], _ => ++cnt); | ||
assert(TestSupervisor.procs === 4); | ||
assert.deepStrictEqual(sv.cast([], 0), [1, 2, 3, 4]); | ||
assert.deepStrictEqual(sv.cast(['a'], 0), [5, 6]); | ||
assert.deepStrictEqual(sv.cast(['a', 'a'], 0), [7]); | ||
assert.deepStrictEqual(sv.cast(['b'], 0), [8]); | ||
assert(cnt === 8); | ||
sv.terminate(['b']); | ||
assert(TestSupervisor.procs === 3); | ||
assert.deepStrictEqual(sv.cast([], 0), []); | ||
assert.deepStrictEqual(sv.cast(['a'], 0), []); | ||
assert.deepStrictEqual(sv.cast(['a', 'a'], 0), []); | ||
assert.deepStrictEqual(sv.cast(['b'], 0), []); | ||
assert(cnt === 8); | ||
sv.call([], 0, 0).then(r => { | ||
assert.deepStrictEqual(r, [9, 10, 11, 12]); | ||
assert(cnt === 12); | ||
sv.terminate(); | ||
it('timeout of processing', function (done) { | ||
let cnt = 1; | ||
const sv = new class TestSupervisor extends Supervisor<string, number, number, number> { }(); | ||
sv.events.exit.once([''], ([, , s, r]) => { | ||
assert(s === 0); | ||
assert(r instanceof Error); | ||
assert(cnt === 1 && ++cnt); | ||
done(); | ||
}); | ||
assert(cnt === 8); | ||
sv.register(['b'], _ => ++cnt); | ||
assert(TestSupervisor.procs === 4); | ||
assert(cnt === 8); | ||
sv.register('', () => new Promise<[number, number]>(() => void 0), 0); | ||
sv.call('', 1, (r, e) => assert(r === void 0) || assert(e instanceof Error) || assert(cnt === 2 && ++cnt), 1e2); | ||
}); | ||
it('retry', function (done) { | ||
let cnt = 0; | ||
class TestSupervisor extends Supervisor<string[], number, number> { | ||
} | ||
assert(TestSupervisor.count === 0); | ||
assert(TestSupervisor.procs === 0); | ||
const sv = new TestSupervisor(); | ||
sv.events.loss.monitor([], done); | ||
sv.events.fail.on([], ([, data]) => assert(++cnt === 2 && data === 0)); | ||
sv.register([], _ => +assert(++cnt === 3) || cnt); | ||
sv.events.exit.on([], ([name, proc, reason]) => reason && sv.register(name, proc)); | ||
assert.deepStrictEqual(sv.cast([], 0, true), [3]); | ||
sv.terminate(); | ||
done(); | ||
}); | ||
it('timeout', function (done) { | ||
let cnt = 0; | ||
const sv = new class TestSupervisor extends Supervisor<string[], number, number> { }(); | ||
sv.call([], 1, 1e2).catch(_ => assert(++cnt === 2) || sv.terminate() || done()); | ||
sv.call([], 2, 0).catch(_ => assert(++cnt === 1)); | ||
}); | ||
it('async', function (done) { | ||
let cnt = 0; | ||
const sv = new class TestSupervisor extends Supervisor<string[], number, number> { }(); | ||
sv.events.loss.monitor([], done); | ||
sv.register([], _ => ++cnt); | ||
sv.call([], 0, 0).then(_ => assert(cnt === 1) || sv.terminate() || done()); | ||
const sv = new class TestSupervisor extends Supervisor<string, number, number, number> { }(); | ||
sv.register('', _ => [++cnt, 0], 0); | ||
sv.call('', 0, _ => assert(cnt === 1) || sv.terminate() || done()); | ||
assert(cnt === 0); | ||
@@ -299,51 +244,22 @@ }); | ||
it('block', function (done) { | ||
let cnt = 0; | ||
const sv = new class TestSupervisor extends Supervisor<string[], number, number> { }(); | ||
sv.events.loss.monitor([], done); | ||
sv.events.fail.on([], ([, data]) => assert(++cnt === 1 && data === 2)); | ||
sv.register([], n => +assert.deepStrictEqual(sv.cast([], 2), []) || +assert(++cnt === 2 && n === 1) || +Tick(() => sv.terminate() || done())); | ||
sv.cast([], 1); | ||
let cnt = 1; | ||
const sv = new class TestSupervisor extends Supervisor<string, number, number, number> { }(); | ||
sv.events.loss.on([''], ([, param]) => assert(cnt === 1 && param === 2 && ++cnt)); | ||
sv.register('', n => assert(sv.cast('', 2) === false) || assert(n === 1) && assert(cnt === 2 && ++cnt) || Tick(() => sv.terminate() || done()) || [0 , 0], 0); | ||
assert(sv.cast('', 1) === true); | ||
}); | ||
it('block async', function (done) { | ||
let cnt = 0; | ||
const sv = new class TestSupervisor extends Supervisor<string[], number, Promise<number>> { }(); | ||
sv.register([], n => new Promise<number>(resolve => void resolve(n))); | ||
sv.events.loss.on([], ([, data]) => assert(++cnt === 1 && data === 2)); | ||
sv.call([], 1, 0).then(r => assert(++cnt === 2 && r.length === 1) || r[0].then(n => assert(++cnt === 4 && n === 1))); | ||
sv.call([], 2, 0).catch(_ => assert(++cnt === 3)); | ||
sv.call([], 3, 1e9).then(r => assert(++cnt === 5 && r.length === 1) || sv.terminate() || done()); | ||
let cnt = 1; | ||
const sv = new class TestSupervisor extends Supervisor<string, number, number, number> { }(); | ||
sv.register('', n => new Promise<[number, number]>(resolve => void resolve([n, 0])), 0); | ||
sv.events.loss.on([''], ([, param]) => assert(cnt === 1 && param === 2 && ++cnt)); | ||
sv.call('', 1, r => assert(r === 1) || assert(cnt === 2 && ++cnt)); | ||
sv.call('', 2, done); | ||
sv.call('', 3, r => assert(r === 3) || assert(cnt === 3 && ++cnt) || sv.terminate() || done(), Infinity); | ||
}); | ||
it('block with dependencies', function (done) { | ||
let cnt = 0; | ||
const sv = new class TestSupervisor extends Supervisor<string[], number, void | PromiseLike<void>> { }({ | ||
dependencies: [ | ||
[['b'], [ | ||
['a'] | ||
]], | ||
[['c'], [ | ||
['a'] | ||
]] | ||
] | ||
}); | ||
sv.events.loss.monitor([], done); | ||
sv.call(['a'], 0, 1e9).then(r => assert(++cnt === 5 && r.length === 1)); | ||
sv.call(['b'], 0, 1e9).then(r => assert(++cnt === 10 && r.length === 1)); | ||
sv.call(['c'], 0, 1e9).then(r => assert(++cnt === 11 && r.length === 1) || sv.terminate() || done()); | ||
sv.call(['d'], 0, 1e9).then(r => assert(++cnt === 6 && r.length === 1)); | ||
sv.call(['e'], 0, 1e9).then(r => assert(++cnt === 7 && r.length === 1)); | ||
sv.register(['a'], _ => { | ||
sv.register(['d'], _ => assert(++cnt === 2)); | ||
sv.register(['b'], _ => assert(++cnt === 8)); | ||
assert(++cnt === 1); | ||
return new Promise<void>(resolve => void resolve(void 0)).then(_ => assert(++cnt === 4)); | ||
}); | ||
sv.register(['c'], _ => assert(++cnt === 9)); | ||
sv.register(['e'], _ => assert(++cnt === 3)); | ||
}); | ||
it('terminate', function (done) { | ||
let cnt = 0; | ||
class TestSupervisor extends Supervisor<string[], number, number> { | ||
class TestSupervisor extends Supervisor<string, number, number, number> { | ||
} | ||
@@ -360,8 +276,9 @@ assert(TestSupervisor.count === 0); | ||
}); | ||
const terminate = sv.register([], _ => _); | ||
const terminate = sv.register('', _ => [0, 0], 0); | ||
sv.terminate(); | ||
terminate(); | ||
sv.terminate(); | ||
assert(cnt === 1); | ||
try { | ||
sv.register([], _ => 0); | ||
sv.register('', _ => [0, 0], 0); | ||
throw 0; | ||
@@ -373,3 +290,3 @@ } | ||
try { | ||
sv.call([], 0); | ||
sv.cast('', 0); | ||
throw 0; | ||
@@ -381,3 +298,3 @@ } | ||
try { | ||
sv.terminate(); | ||
sv.call('', 0, () => 0); | ||
throw 0; | ||
@@ -388,2 +305,4 @@ } | ||
} | ||
assert(TestSupervisor.count === 0); | ||
assert(TestSupervisor.procs === 0); | ||
done(); | ||
@@ -390,0 +309,0 @@ }); |
@@ -1,27 +0,9 @@ | ||
import {Supervisor as ISupervisor, SupervisorSettings} from 'spica'; | ||
import {Supervisor as ISupervisor} from 'spica'; | ||
import {Observable} from './observable'; | ||
import {DataMap} from './collection/datamap'; | ||
import {Tick} from './tick'; | ||
import {isThenable} from './thenable'; | ||
import {concat} from './concat'; | ||
import {sqid} from './sqid'; | ||
import {noop} from './noop'; | ||
interface WorkerSharedResources<T extends string[], D, R> { | ||
procs: Observable<T, WorkerCommand<T, D>, R>; | ||
dependenciesStack: T[]; | ||
allRefsCache?: [T, (data: WorkerCommand<T, D>) => R, boolean][]; | ||
} | ||
export namespace Supervisor { | ||
export namespace Event { | ||
export namespace Data { | ||
export type Exec<T extends string[], D, R> = ISupervisor.Event.Data.Exec<T, D, R>; | ||
export type Fail<T extends string[], D> = ISupervisor.Event.Data.Fail<T, D>; | ||
export type Loss<T extends string[], D> = ISupervisor.Event.Data.Loss<T, D>; | ||
export type Exit<T extends string[], D, R> = ISupervisor.Event.Data.Exit<T, D, R>; | ||
} | ||
} | ||
} | ||
export abstract class Supervisor<T extends string[], D, R> implements ISupervisor<T, D, R> { | ||
export abstract class Supervisor<N extends string, P, R, S> implements ISupervisor<N, P, R, S> { | ||
public static count: number = 0; | ||
@@ -31,11 +13,7 @@ public static procs: number = 0; | ||
name = '', | ||
dependencies = [], | ||
retry = false, | ||
timeout = 0, | ||
destructor = noop | ||
}: SupervisorSettings<T> = {}) { | ||
if (this.constructor === Supervisor) throw new Error('Spica: Supervisor: Cannot instantiate abstract classes.'); | ||
}: Supervisor.Settings<N> = {}) { | ||
if (this.constructor === Supervisor) throw new Error(`Spica: Supervisor: <${this.id}/${this.name}>: Cannot instantiate abstract classes.`); | ||
this.name = name; | ||
void dependencies.reduce<void>((_, [namespace, deps]) => void this.deps.set(namespace, deps), void 0); | ||
this.retry = retry; | ||
this.timeout = timeout; | ||
@@ -49,7 +27,4 @@ this.destructor_ = destructor; | ||
this.alive = false; | ||
assert(this.procs.refs(<T><any[]>[]).length === 0); | ||
while (this.queue.length > 0) { | ||
const [namespace, data] = this.queue.shift()!; | ||
void this.events.loss.emit(namespace, [namespace, data]); | ||
} | ||
assert(this.procs.refs([]).length === 0); | ||
void this.drain(); | ||
try { | ||
@@ -65,14 +40,12 @@ void this.destructor_(reason); | ||
} | ||
public readonly id: string = sqid(); | ||
public readonly name: string; | ||
private readonly deps: DataMap<T, T[]> = new DataMap<T, T[]>(); | ||
private readonly retry: boolean; | ||
private readonly timeout: number; | ||
private readonly destructor_: (reason?: any) => any; | ||
private readonly destructor_: (reason: any) => any; | ||
public readonly events = { | ||
exec: new Observable<T, Supervisor.Event.Data.Exec<T, D, R>, any>(), | ||
fail: new Observable<T, Supervisor.Event.Data.Fail<T, D>, any>(), | ||
loss: new Observable<T, Supervisor.Event.Data.Loss<T, D>, any>(), | ||
exit: new Observable<T, Supervisor.Event.Data.Exit<T, D, R>, any>() | ||
init: new Observable<never[] | [N], Supervisor.Event.Data.Init<N, P, R, S>, any>(), | ||
loss: new Observable<never[] | [N], Supervisor.Event.Data.Loss<N, P>, any>(), | ||
exit: new Observable<never[] | [N], Supervisor.Event.Data.Exit<N, P, R, S>, any>() | ||
}; | ||
private readonly procs: Observable<T, WorkerCommand<T, D>, R> = new Observable<T, WorkerCommand<T, D>, R>(); | ||
private readonly procs: Observable<never[] | [N], WorkerCommand<P>, R | PromiseLike<R>> = new Observable<[N], WorkerCommand<P>, R | PromiseLike<R>>(); | ||
private alive = true; | ||
@@ -91,49 +64,52 @@ private registerable = true; | ||
} | ||
private readonly workerSharedResource: WorkerSharedResources<T, D, R> = { | ||
procs: this.procs, | ||
dependenciesStack: [] | ||
private readonly workerSharedResource: WorkerSharedResources<N, P, R> = { | ||
procs: this.procs | ||
}; | ||
public register(namespace: T, process: (data: D) => R): (reason?: any) => void { | ||
public register(name: N, process: Supervisor.Process<P, R, S> | Supervisor.Process.Call<P, R, S>, state: S): (reason?: any) => void { | ||
void this.checkState(); | ||
if (!this.registerable) throw new Error(`Spica: Supervisor: Supervisor ${this.name} cannot register process during the exiting.`); | ||
namespace = <T>concat([], namespace); | ||
if (!this.registerable) throw new Error(`Spica: Supervisor: <${this.id}/${this.name}/${name}>: Cannot register a process after a supervisor is terminated.`); | ||
if (this.procs.refs([name]).length > 0) throw new Error(`Spica: Supervisor: <${this.id}/${this.name}/${name}>: Cannot register a process multiply using the same name.`); | ||
void this.schedule(); | ||
return new Worker<T, D, R>(this, this.workerSharedResource, namespace, process, this.deps.get(namespace) || []).terminate; | ||
process = typeof process === 'function' | ||
? { | ||
init: state => state, | ||
call: process, | ||
exit: _ => void 0 | ||
} | ||
: process; | ||
return new Worker<N, P, R, S>(this, this.workerSharedResource, name, process, state).terminate; | ||
} | ||
public call(namespace: T, data: D, timeout = this.timeout): Promise<R[]> { | ||
public call(name: N, param: P, callback: (reply: R, error?: Error) => void, timeout = this.timeout): void { | ||
void this.checkState(); | ||
namespace = <T>concat([], namespace); | ||
return new Promise<R[]>((resolve, reject) => { | ||
void this.queue.push([ | ||
namespace, | ||
data, | ||
results => | ||
results.length === 0 | ||
? void reject(data) | ||
: void resolve(results), | ||
timeout, | ||
Date.now() | ||
]); | ||
void this.schedule(); | ||
if (timeout > 0 === false) return; | ||
void setTimeout(() => void this.drain(namespace), timeout + 9); | ||
}); | ||
void this.queue.push([ | ||
name, | ||
param, | ||
callback, | ||
timeout, | ||
Date.now() | ||
]); | ||
void this.schedule(); | ||
if (timeout < Infinity === false) return; | ||
if (timeout > 0 === false) return; | ||
void setTimeout(() => void this.drain(name), timeout + 9); | ||
} | ||
public cast(namespace: T, data: D, retry = this.retry): R[] { | ||
public cast(name: N, param: P, timeout = this.timeout): boolean { | ||
void this.checkState(); | ||
const results = this.procs.reflect(namespace, new WorkerCommand.Call(data)); | ||
const results = this.procs.reflect([name], new WorkerCommand.Call(param, timeout)); | ||
assert(results.length <= 1); | ||
if (results.length === 0) { | ||
void this.events.fail.emit(namespace, [namespace, data]); | ||
void this.events.loss.emit([name], [name, param]); | ||
} | ||
return results.length > 0 || !retry ? results : this.cast(namespace, data, false); | ||
return results.length > 0; | ||
} | ||
public refs(namespace: T): [T, (data: D) => R, (reason: any) => void][] { | ||
public refs(name?: N): [N, Supervisor.Process<P, R, S>, S, (reason: any) => void][] { | ||
void this.checkState(); | ||
return this.procs.refs(namespace) | ||
.map<[T, (data: D) => R, (reason: any) => void]>(([, recv]) => { | ||
const worker: Worker<T, D, R> = <any>recv(new WorkerCommand.Self()); | ||
return this.procs.refs(name === void 0 ? [] : [name]) | ||
.map<[N, Supervisor.Process<P, R, S>, S, (reason: any) => void]>(([, recv]) => { | ||
const worker: Worker<N, P, R, S> = <any>recv(new WorkerCommand.Self()); | ||
assert(worker instanceof Worker); | ||
return [ | ||
worker.namespace, | ||
worker.name, | ||
worker.process, | ||
worker.state, | ||
worker.terminate | ||
@@ -143,13 +119,13 @@ ]; | ||
} | ||
public terminate(namespace?: T, reason?: any): void { | ||
void this.checkState(); | ||
assert(this.registerable === true); | ||
if (namespace === void 0) { | ||
public terminate(name?: N, reason?: any): void { | ||
if (!this.registerable) return; | ||
if (name === void 0) { | ||
this.registerable = false; | ||
} | ||
const namespace = name === void 0 ? [] : <[N]>[name]; | ||
void this.procs | ||
.emit(namespace || <T><any[]>[], new WorkerCommand.Exit(reason)); | ||
.emit(namespace, new WorkerCommand.Exit(reason)); | ||
void this.procs | ||
.off(namespace || <T><any[]>[]); | ||
if (namespace === void 0) { | ||
.off(namespace); | ||
if (name === void 0) { | ||
void this.destructor(reason); | ||
@@ -159,29 +135,45 @@ } | ||
private checkState(): void { | ||
if (!this.alive) throw new Error(`Spica: Supervisor: Supervisor ${this.name} already exited.`); | ||
if (!this.alive) throw new Error(`Spica: Supervisor: <${this.id}/${this.name}>: A supervisor is already terminated.`); | ||
} | ||
private readonly queue: [T, D, (results: R[]) => void, number, number][] = []; | ||
private drain(target: T = <T><any[]>[]): void { | ||
private readonly queue: [N, P, (reply: R, error?: Error) => void, number, number][] = []; | ||
private drain(target?: N): void { | ||
const now = Date.now(); | ||
for (let i = 0; i < this.queue.length; ++i) { | ||
const [namespace, data, callback, timeout, since] = this.queue[i]; | ||
const results = target.every((n, i) => n === namespace[i]) | ||
? this.procs.reflect(namespace, new WorkerCommand.Call(data)) | ||
const [name, param, callback, timeout, since] = this.queue[i]; | ||
const replies: [R | PromiseLike<R>] | never[] = target === void 0 || target === name | ||
? <[R | PromiseLike<R>]>this.procs.reflect([name], new WorkerCommand.Call(param, since + timeout - now)) | ||
: []; | ||
if (results.length === 0) { | ||
void this.events.fail.emit(namespace, [namespace, data]); | ||
} | ||
if (results.length === 0 && now < since + timeout) continue; | ||
i === 0 ? void this.queue.shift() : void this.queue.splice(i, 1); | ||
assert(replies.length <= 1); | ||
if (this.alive && replies.length === 0 && now < since + timeout) continue; | ||
i === 0 | ||
? void this.queue.shift() | ||
: void this.queue.splice(i, 1); | ||
void --i; | ||
if (results.length === 0) { | ||
void this.events.loss.emit(namespace, [namespace, data]); | ||
if (replies.length === 0) { | ||
void this.events.loss.emit([name], [name, param]); | ||
} | ||
if (!callback) continue; | ||
try { | ||
void callback(results); | ||
if (this.alive && replies.length > 0) { | ||
const [reply] = replies; | ||
if (isThenable(reply)) { | ||
void Promise.resolve(reply) | ||
.then( | ||
reply => | ||
this.alive | ||
? void callback(reply) | ||
: void callback(<any>void 0, new Error(`Spica: Supervisor: <${this.id}/${this.name}/${name}>: A request is expired.`)), | ||
reason => | ||
void callback(<any>void 0, reason)); | ||
} | ||
else { | ||
try { | ||
void callback(reply); | ||
} | ||
catch (reason) { | ||
void console.error(reason); | ||
} | ||
} | ||
} | ||
catch (err) { | ||
void console.error(err); | ||
assert(!console.info(err + '')); | ||
else { | ||
void callback(<any>void 0, new Error(`Spica: Supervisor: <${this.id}/${this.name}/${name}>: A request is expired.`)); | ||
} | ||
@@ -191,41 +183,38 @@ } | ||
} | ||
export namespace Supervisor { | ||
export type Settings<N extends string> = ISupervisor.Settings<N>; | ||
export type Process<P, R, S> = ISupervisor.Process<P, R, S>; | ||
export namespace Process { | ||
export type Init<S> = ISupervisor.Process.Init<S>; | ||
export type Call<P, R, S> = ISupervisor.Process.Call<P, R, S>; | ||
export type Exit<S> = ISupervisor.Process.Exit<S>; | ||
} | ||
export import Event = ISupervisor.Event; | ||
} | ||
type WorkerCommand<T, D> | ||
interface WorkerSharedResources<N extends string, P, R> { | ||
procs: Observable<never[] | [N], WorkerCommand<P>, R | PromiseLike<R>>; | ||
} | ||
type WorkerCommand<P> | ||
= WorkerCommand.Self | ||
| WorkerCommand.Deps<T> | ||
| WorkerCommand.Call<D> | ||
| WorkerCommand.Call<P> | ||
| WorkerCommand.Exit; | ||
namespace WorkerCommand { | ||
abstract class AbstractCommand { | ||
private readonly WORKER_COMMAND: void; | ||
constructor() { | ||
void this.WORKER_COMMAND; | ||
} | ||
} | ||
export class Self extends AbstractCommand { | ||
export class Self { | ||
private readonly COMMAND: this; | ||
constructor() { | ||
super(); | ||
void this.COMMAND; | ||
} | ||
} | ||
export class Deps<T> extends AbstractCommand { | ||
export class Call<P> { | ||
private readonly COMMAND: this; | ||
constructor(public readonly namespace: T) { | ||
super(); | ||
constructor(public readonly param: P, public readonly timeout: number) { | ||
void this.COMMAND; | ||
} | ||
} | ||
export class Call<D> extends AbstractCommand { | ||
export class Exit { | ||
private readonly COMMAND: this; | ||
constructor(public readonly data: D) { | ||
super(); | ||
void this.COMMAND; | ||
} | ||
} | ||
export class Exit extends AbstractCommand { | ||
private readonly COMMAND: this; | ||
constructor(public readonly reason: any) { | ||
super(); | ||
void this.COMMAND; | ||
@@ -236,17 +225,18 @@ } | ||
class Worker<T extends string[], D, R> { | ||
class Worker<N extends string, P, R, S> { | ||
constructor( | ||
private readonly sv: Supervisor<T, D, R>, | ||
private readonly sharedResource: WorkerSharedResources<T, D, R>, | ||
public readonly namespace: T, | ||
public readonly process: (data: D) => R, | ||
private readonly dependencies: T[] | ||
private readonly sv: Supervisor<N, P, R, S>, | ||
private readonly sharedResource: WorkerSharedResources<N, P, R>, | ||
public readonly name: N, | ||
public readonly process: Supervisor.Process<P, R, S>, | ||
public state: S | ||
) { | ||
this.receive = (cmd: WorkerCommand<T, D>) => Worker.prototype.receive.call(this, cmd); // identifier | ||
assert(process.init && process.exit); | ||
// fix the context, and that must be an immutable unique identifier. | ||
this.receive = (cmd: WorkerCommand<P>) => Worker.prototype.receive.call(this, cmd); | ||
this.terminate = (reason: any) => Worker.prototype.terminate.call(this, reason); | ||
this.sharedResource.allRefsCache = void 0; | ||
void ++(<typeof Supervisor>this.sv.constructor).procs; | ||
void this.sharedResource.procs | ||
.on(namespace, this.receive); | ||
.on([name], this.receive); | ||
} | ||
@@ -256,9 +246,16 @@ private destructor(reason: any): void { | ||
void this.sharedResource.procs | ||
.off(this.namespace, this.receive); | ||
.off([this.name], this.receive); | ||
this.alive = false; | ||
void --(<typeof Supervisor>this.sv.constructor).procs; | ||
this.sharedResource.allRefsCache = void 0; | ||
void Object.freeze(this); | ||
void this.sv.events.exit | ||
.emit(this.namespace, [this.namespace, this.process, reason]); | ||
try { | ||
void this.process.exit(this.state, reason); | ||
void this.sv.events.exit | ||
.emit([this.name], [this.name, this.process, this.state, reason]); | ||
} | ||
catch (reason) { | ||
void this.sv.events.exit | ||
.emit([this.name], [this.name, this.process, this.state, reason]); | ||
void this.sv.terminate(void 0, reason); | ||
} | ||
} | ||
@@ -268,61 +265,45 @@ private alive = true; | ||
private concurrency: number = 1; | ||
private tryDependencyResolving(): void { | ||
if (this.receive(new WorkerCommand.Deps(this.namespace))) { | ||
this.sharedResource.dependenciesStack = []; | ||
return; | ||
} | ||
else { | ||
this.sharedResource.dependenciesStack = []; | ||
throw void 0; | ||
} | ||
} | ||
public receive(cmd: WorkerCommand.Self): Worker<T, D, R> | ||
public receive(cmd: WorkerCommand.Deps<T>): boolean | ||
public receive(cmd: WorkerCommand<T, D>): R | ||
public receive(cmd: WorkerCommand<T, D>): any { | ||
public receive(cmd: WorkerCommand.Self): Worker<N, P, R, S> | ||
public receive(cmd: WorkerCommand<P>): R | PromiseLike<R> | ||
public receive(cmd: WorkerCommand<P>): Worker<N, P, R, S> | boolean | R | PromiseLike<R> { | ||
void this.checkState(); | ||
if (cmd instanceof WorkerCommand.Self) { | ||
return this; | ||
} | ||
if (cmd instanceof WorkerCommand.Deps) { | ||
if (cmd.namespace.length !== this.namespace.length) return false; | ||
if (this.concurrency === 0) return false; | ||
for (const stacked of this.sharedResource.dependenciesStack) { | ||
if (equal(this.namespace, stacked)) return true; | ||
} | ||
void this.sharedResource.dependenciesStack.push(this.namespace); | ||
return this.dependencies | ||
.every(dep => | ||
(this.sharedResource.allRefsCache = this.sharedResource.allRefsCache || this.sharedResource.procs.refs(<T><any[]>[])) | ||
.some(([ns, proc]) => equal(ns, dep) && !!proc(new WorkerCommand.Deps(dep))) | ||
); | ||
} | ||
if (cmd instanceof WorkerCommand.Call) { | ||
if (this.concurrency === 0) throw void 0; // cancel | ||
void this.tryDependencyResolving(); | ||
if (!this.called) { | ||
this.called = true; | ||
void this.sv.events.exec | ||
.emit(this.namespace, [this.namespace, this.process]); | ||
} | ||
try { | ||
void --this.concurrency; | ||
const result = (0, this.process)(cmd.data); | ||
if (!this.called) { | ||
this.called = true; | ||
void this.sv.events.init | ||
.emit([this.name], [this.name, this.process, this.state]); | ||
this.state = this.process.init(this.state); | ||
} | ||
const result = this.process.call(cmd.param, this.state); | ||
if (isThenable(result)) { | ||
void (<PromiseLike<R>><any>result) | ||
.then(_ => { | ||
void this.sv.schedule(); | ||
if (!this.alive) return; | ||
void ++this.concurrency; | ||
}, reason => { | ||
void this.sv.schedule(); | ||
if (!this.alive) return; | ||
void ++this.concurrency; | ||
void this.terminate(reason); | ||
}); | ||
return new Promise<[R, S]>((resolve, reject) => { | ||
void result.then(resolve, reject); | ||
if (cmd.timeout < Infinity === false) return; | ||
void setTimeout(() => void reject(new Error(`Spica: Supervisor: <${this.sv.id}/${this.sv.name}/${this.name}>: Timeout while processing.`)), cmd.timeout); | ||
}) | ||
.then( | ||
([reply, state]) => { | ||
void ++this.concurrency; | ||
void this.sv.schedule(); | ||
if (!this.alive) throw void 0; | ||
this.state = state; | ||
return reply; | ||
}, | ||
reason => { | ||
void ++this.concurrency; | ||
void this.sv.schedule(); | ||
if (!this.alive) throw reason; | ||
void this.terminate(reason); | ||
throw reason; | ||
}); | ||
} | ||
else { | ||
void ++this.concurrency; | ||
const [reply, state] = result; | ||
this.state = state; | ||
return reply; | ||
} | ||
return result; | ||
} | ||
@@ -338,3 +319,6 @@ catch (reason) { | ||
} | ||
throw new TypeError(`Spica: Supervisor: Invalid command: ${cmd}`); | ||
if (cmd instanceof WorkerCommand.Self) { | ||
return this; | ||
} | ||
throw new TypeError(`Spica: Supervisor: <${this.sv.id}/${this.sv.name}/${this.name}>: Invalid command: ${cmd}`); | ||
} | ||
@@ -345,13 +329,4 @@ public terminate(reason: any): void { | ||
private checkState(): void { | ||
if (!this.alive) throw new Error(`Spica: Supervisor: Process ${this.namespace}/${this.process} already exited.`); | ||
if (!this.alive) throw new Error(`Spica: Supervisor: <${this.sv.id}/${this.sv.name}/${this.name}>: A process is already terminated:\n${this.process}`); | ||
} | ||
} | ||
function equal<T>(a: T[], b: T[]): boolean { | ||
if (a === b) return true; | ||
if (a.length !== b.length) return false; | ||
for (let i = 0; i < a.length; ++i) { | ||
if (a[i] !== b[i]) return false; | ||
} | ||
return true; | ||
} |
@@ -1,32 +0,33 @@ | ||
namespace TICK { | ||
export const queue = enqueue; | ||
const Queue: ((...args: any[]) => any)[] = []; | ||
const Queue: ((...args: any[]) => any)[] = []; | ||
let Reservation = 0; | ||
let scheduled = false; | ||
function enqueue(fn: (_?: void) => any): void { | ||
assert(typeof fn === 'function'); | ||
void Queue.push(fn); | ||
void schedule(); | ||
} | ||
function dequeue(): void { | ||
void schedule(); | ||
void --Reservation; | ||
let task = Queue.length; | ||
while (task-- > 0) { | ||
void Queue.shift()!(); | ||
function enqueue(fn: (_?: void) => any): void { | ||
assert(typeof fn === 'function'); | ||
void Queue.push(fn); | ||
void schedule(); | ||
} | ||
function dequeue(): void { | ||
let rem = Queue.length; | ||
while (true) { | ||
try { | ||
while (rem > 0) { | ||
void --rem; | ||
void Queue.shift()!(); | ||
} | ||
} | ||
} | ||
const Delays = [0, 4, 10, 20, 25].reverse(); | ||
function schedule(): void { | ||
if (Queue.length === 0) return; | ||
assert(0 <= Reservation && Reservation <= Delays.length); | ||
while (Reservation < Delays.length) { | ||
void setTimeout(dequeue, Delays[Reservation % Delays.length]); | ||
void ++Reservation; | ||
catch (e) { | ||
console.error(e); | ||
continue; | ||
} | ||
assert(0 <= Reservation && Reservation <= Delays.length); | ||
break; | ||
} | ||
scheduled = false; | ||
} | ||
function schedule(): void { | ||
if (scheduled) return; | ||
if (Queue.length === 0) return; | ||
void Promise.resolve().then(dequeue); | ||
scheduled = true; | ||
} | ||
@@ -36,3 +37,3 @@ | ||
export const Tick = IS_NODE | ||
? <typeof TICK.queue>Function('return fn => process.nextTick(fn)')() | ||
: TICK.queue; | ||
? <typeof enqueue>Function('return fn => process.nextTick(fn)')() | ||
: enqueue; |
@@ -12,3 +12,3 @@ import { | ||
HList, HNil, | ||
DataMap, AttrMap, | ||
DataMap, CacheMap, AttrMap, | ||
Mixin, | ||
@@ -131,2 +131,6 @@ Tick, | ||
it('CacheMap', function () { | ||
assert(typeof CacheMap === 'function'); | ||
}); | ||
it('AttrMap', function () { | ||
@@ -190,18 +194,2 @@ assert(typeof AttrMap === 'function'); | ||
describe('power-assert', function () { | ||
it('assertion self-check', function (done) { | ||
setTimeout(function () { | ||
try { | ||
console.log(assert(!false === !true), assert); // LOG: undefined, function powerAssert() { ... } | ||
} | ||
catch (e) { | ||
done(); | ||
return; | ||
} | ||
throw new Error('WARNING!: assert function does not work.'); | ||
}, 1); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
397779
139
9813
48