Comparing version 0.0.30 to 0.0.31
@@ -1,3 +0,3 @@ | ||
/*! spica v0.0.30 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+""),n.childrenList=n.childrenList.sort(),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){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(){this.store=new Map,this.weakstore=new WeakMap}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.weakstore.has(e)?this.weakstore.get(e):this.stringifyObject(e)||this.weakstore.set(e,t.sqid()))+" }"}},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&&void 0!==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,n){return n?e.bind(function(e){return n.fmap(function(n){return 0===e.length?e(n):r.curry(e)(n)})}):function(n){return e.bind(function(e){return n.fmap(function(n){return 0===e.length?e(n):r.curry(e)(n)})})}}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,n){return n?e.bind(n):function(n){return e.bind(n)}}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)}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}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)}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)}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}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}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,t){e.call(this,r),this.cons=n,this.memory=t}return __extends(n,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){return void 0===n&&(n=0),n<e.length?t(e[n],++n):t()})},n}(t.Sequence);Object.defineProperty(n,"__esModule",{value:!0}),n.default=r}),define("src/lib/monad/sequence/member/static/read",["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.read=function(e){return new t.Sequence(function(n,t){return e.length>0?t(e.shift(),e):t()})},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){return void 0===n&&(n=0),0===e.length?t():t(e[n],++n%e.length)})},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){switch(void 0===e&&(e=function(){return Math.random()}),!0){case Array.isArray(e):return this.random().map(function(n){return e[n*e.length|0]});default:return new t.Sequence(function(n,t){return t(e(),NaN)})}},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 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.memory?this.memory.has(n)?this.memory.get(n):this.memory.set(n,this.cons(e,t.Sequence.Data.cons)).get(n):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=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.memoize=function(e){return void 0===e&&(e=this.memory||new Map),new t.Sequence(this.cons,this.memory||e)},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.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","src/lib/concat"],function(e,n,t,r){"use strict";function i(e){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];return r.concat([e],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})}n.compose=i}),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/read","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/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,g,k,T,M,O,I,j,P,E,R,N,D,z,C,A,L,F,W){"use strict";n.Sequence=t.Sequence,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,g.default,k.default,T.default,M.default,O.default,I.default,j.default,P.default,E.default,R.default,N.default,D.default,z.default,C.default,A.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(){this.store=new WeakMap}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 Map).get(e);return void r.set(n,t),this},e.prototype.has=function(e,n){return this.store.has(e)&&this.store.get(e).has(n)},e.prototype.delete=function(e,n){return void 0===n?this.store.delete(e):!!this.store.has(e)&&this.store.get(e).delete(n)},e}();n.AttrMap=t}),define("src/lib/collection/relationmap",["require","exports"],function(e,n){"use strict";var t=function(){function e(){this.store=new WeakMap}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 WeakMap).get(e);return void r.set(n,t),this},e.prototype.has=function(e,n){return this.store.has(e)&&this.store.get(e).has(n)},e.prototype.delete=function(e,n){return void 0===n?this.store.delete(e):!!this.store.has(e)&&this.store.get(e).delete(n)},e}();n.RelationMap=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.apply(n.apply(this,arguments)||this,arguments)}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/collection/relationmap","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,_,x){"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.RelationMap=h.RelationMap,n.Mixin=v.Mixin,n.Tick=m.Tick,n.FINGERPRINT=q.FINGERPRINT,n.uuid=b.v4,n.sqid=y.sqid,n.assign=S.assign,n.clone=S.clone,n.extend=S.extend,n.concat=_.concat,n.sort=x.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.31 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+""),n.childrenList=n.childrenList.sort(),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&&void 0!==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,t){e.call(this,r),this.cons=n,this.memory=t}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,new Map]:n,i=r[0],u=r[1],o=r[2],c=o.has(u)?o.get(u):o.set(u,i.next()).get(u);return c.done?t():t(c.value,[i,u+1,o])})},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,new Map]:t,u=i[0],o=i[1],c=i[2],s=c.has(o)?c.get(o):c.set(o,u.next()).get(o);return s.done?n([e[Symbol.iterator](),o+1,c],r):r(s.value,[u,o+1,c])})},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.memory?this.memory.has(n)?this.memory.get(n):this.memory.set(n,this.cons(e,t.Sequence.Data.cons)).get(n):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=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n.prototype.memoize=function(e){return void 0===e&&(e=this.memory||new Map), | ||
new t.Sequence(this.cons,this.memory||e)},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.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/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){"use strict";n.Sequence=t.Sequence,void F.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,x.default,_.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)}),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,x){"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=x.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)}); |
@@ -33,4 +33,5 @@ module.exports = function (config) { | ||
autoWatchBatchDelay: 500, | ||
browsers: ['Chrome'] | ||
browsers: ['Chrome'], | ||
browserNoActivityTimeout: 100 * 1e3 | ||
}); | ||
}; |
{ | ||
"name": "spica", | ||
"version": "0.0.30", | ||
"version": "0.0.31", | ||
"description": "Supervisor, Observable, Sequence, Maybe, Either and some utils.", | ||
@@ -63,3 +63,3 @@ "private": false, | ||
"run-sequence": "^1.2.2", | ||
"typescript": "2.1.0-dev.20160829" | ||
"typescript": "2.1.0-dev.20160903" | ||
}, | ||
@@ -66,0 +66,0 @@ "scripts": { |
@@ -17,3 +17,3 @@ # Spica | ||
[spica.d.ts](typings/spica.d.ts) | ||
[spica.d.ts](spica.d.ts) | ||
@@ -32,3 +32,2 @@ - Supervisor | ||
- AttrMap | ||
- RelationMap | ||
- Mixin | ||
@@ -35,0 +34,0 @@ - Tick |
120
spica.d.ts
@@ -20,11 +20,11 @@ /** | ||
export abstract class Supervisor<T extends string[], D, R> { | ||
static count: number; | ||
static procs: number; | ||
static readonly count: number; | ||
static readonly procs: number; | ||
constructor(settings?: SupervisorSettings<T>) | ||
name: string; | ||
events: { | ||
exec: Observer<T, Supervisor.Event.Data.Exec<T, D, R>, any>; | ||
fail: Observer<T, Supervisor.Event.Data.Fail<T, D>, any>; | ||
loss: Observer<T, Supervisor.Event.Data.Loss<T, D>, any>; | ||
exit: Observer<T, Supervisor.Event.Data.Exit<T, D, R>, any>; | ||
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>; | ||
}; | ||
@@ -38,7 +38,7 @@ register(namespace: T, process: (data: D) => R): (reason?: any) => void; | ||
export interface SupervisorSettings<T> { | ||
name?: string; | ||
dependencies?: [T, T[]][]; | ||
retry?: boolean; | ||
timeout?: number; | ||
destructor?: (reason?: any) => any; | ||
readonly name?: string; | ||
readonly dependencies?: [T, T[]][]; | ||
readonly retry?: boolean; | ||
readonly timeout?: number; | ||
readonly destructor?: (reason?: any) => any; | ||
} | ||
@@ -71,10 +71,11 @@ | ||
export class Cancelable<L> { | ||
listeners: Set<(reason: L) => void>; | ||
cancel: (reason: L) => void; | ||
promise: <T>(val: T) => Promise<T>; | ||
maybe: <T>(val: T) => Maybe<T>; | ||
either: <R>(val: R) => Either<L, R>; | ||
readonly listeners: Set<(reason: L) => void>; | ||
readonly cancel: (reason: L) => void; | ||
readonly promise: <T>(val: T) => Promise<T>; | ||
readonly maybe: <T>(val: T) => Maybe<T>; | ||
readonly either: <R>(val: R) => Either<L, R>; | ||
} | ||
abstract class Lazy<a> { | ||
abstract extract(): any; | ||
} | ||
@@ -111,8 +112,7 @@ abstract class Functor<a> extends Lazy<a> { | ||
export class Sequence<a, z> extends MonadPlus<a> { | ||
static from<a>(as: a[]): Sequence<a, number>; | ||
static read<a>(as: a[]): Sequence<a, a[]>; | ||
static cycle<a>(as: a[]): Sequence<a, number>; | ||
static random(): Sequence<number, number>; | ||
static random<a>(gen: () => a): Sequence<a, number>; | ||
export class Sequence<a, z> extends MonadPlus<a> implements Iterable<a> { | ||
static from<a>(as: Iterable<a>): Sequence<a, [Iterator<a>, number, Map<number, IteratorResult<a>>]>; | ||
static cycle<a>(as: Iterable<a>): Sequence<a, [Iterator<a>, number, Map<number, IteratorResult<a>>]>; | ||
static random(): Sequence<number, [Iterator<number>, number, Map<number, IteratorResult<number>>]>; | ||
static random<a>(gen: () => a): Sequence<a, [Iterator<a>, number, Map<number, IteratorResult<a>>]>; | ||
static random<a>(as: a[]): Sequence<a, Sequence.Iterator<number>>; | ||
@@ -132,9 +132,10 @@ static zip<a, b>(a: Sequence<a, any>, b: Sequence<b, any>): Sequence<[a, b], [Sequence.Iterator<a>, Sequence.Iterator<b>]>; | ||
static bind<a>(m: Sequence<a, any>): <b>(f: (a: a) => Sequence<b, any>) => Sequence<b, Sequence.Iterator<a>>; | ||
static mempty: Sequence<any, any>; | ||
static readonly mempty: Sequence<any, any>; | ||
static mappend<a>(l: Sequence<a, any>, r: Sequence<a, any>): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]>; | ||
static mconcat<a>(as: Sequence<a, any>[]): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]>; | ||
static mzero: Sequence<any, any>; | ||
static mconcat<a>(as: Iterable<Sequence<a, any>>): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]>; | ||
static readonly mzero: Sequence<any, any>; | ||
static mplus<a>(l: Sequence<a, any>, r: Sequence<a, any>): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]>; | ||
constructor(cons: (z: z, cons: (a?: a, z?: z) => Sequence.Data<a, z>) => Sequence.Data<a, z>); | ||
extract(): a[]; | ||
[Symbol.iterator](): Iterator<a>; | ||
iterate(): Sequence.Thunk<a>; | ||
@@ -173,3 +174,3 @@ fmap<b>(f: (a: a) => b): Sequence<b, Sequence.Iterator<a>>; | ||
export abstract class Maybe<a> extends MonadPlus<a> { | ||
protected MAYBE: Just<a> | Nothing; | ||
private readonly MAYBE: Just<a> | Nothing; | ||
fmap<b>(f: (a: a) => b): Maybe<b>; | ||
@@ -210,4 +211,3 @@ ap<a, z>(this: Maybe<(a: a) => z>, a: Maybe<a>): Maybe<z>; | ||
export class Just<a> extends Maybe<a> { | ||
protected MAYBE: Just<a>; | ||
protected JUST: a; | ||
private readonly JUST: a; | ||
bind(f: (a: a) => Nothing): Maybe<a>; | ||
@@ -220,4 +220,3 @@ bind<b>(f: (a: a) => Maybe<b> | Nothing): Maybe<b>; | ||
export class Nothing extends Maybe<any> { | ||
protected MAYBE: Nothing; | ||
protected NOTHING: void; | ||
private readonly NOTHING: void; | ||
bind(f: (a: any) => Nothing): Nothing; | ||
@@ -249,3 +248,3 @@ bind<b>(f: (a: any) => Maybe<b> | Nothing): Maybe<b>; | ||
export abstract class Either<a, b> extends Monad<b> { | ||
protected EITHER: Left<a> | Right<b>; | ||
private readonly EITHER: Left<a> | Right<b>; | ||
fmap<c>(f: (b: b) => c): Either<a, c>; | ||
@@ -278,4 +277,3 @@ ap<b, z>(this: Either<a, (b: b) => z>, b: Either<a, b>): Either<a, z>; | ||
export class Left<a> extends Either<a, any> { | ||
protected EITHER: Left<a>; | ||
protected LEFT: a; | ||
private readonly LEFT: a; | ||
bind(_: (b: any) => Left<a>): Left<a>; | ||
@@ -288,4 +286,3 @@ bind<b>(f: (b: b) => Either<a, b>): Either<a, b>; | ||
export class Right<b> extends Either<any, b> { | ||
protected EITHER: Right<b>; | ||
protected RIGHT: b; | ||
private readonly RIGHT: b; | ||
bind<c>(f: (b: b) => Right<c>): Right<c>; | ||
@@ -340,3 +337,3 @@ bind<a, c>(f: (b: b) => Either<a, c>): Either<a, c>; | ||
} | ||
export const curry: { | ||
interface Curry { | ||
<z>(f: () => z, ctx?: any): () => z; | ||
@@ -348,3 +345,4 @@ <a, z>(f: (a: a) => z, ctx?: any): Curried1<a, z>; | ||
<a, b, c, d, e, z>(f: (a: a, b: b, c: c, d: d, e: e) => z, ctx?: any): Curried5<a, b, c, d, e, z>; | ||
}; | ||
} | ||
export const curry: Curry; | ||
export function flip<a, b, c>(f: (a: a) => (b: b) => c): Curried2<b, a, c> | ||
@@ -355,7 +353,7 @@ export function flip<a, b, c>(f: (a: a, b: b) => c): Curried2<b, a, c> | ||
export class Nil { | ||
private NIL: void; | ||
private readonly NIL: void; | ||
push<a>(a: a): List<a, Nil>; | ||
} | ||
class Cons<a, c extends Nil | List<a, any>> { | ||
private CONS: a; | ||
private readonly CONS: a; | ||
push(a: a): List<a, this>; | ||
@@ -383,7 +381,7 @@ head(): a; | ||
export class HNil { | ||
private NIL: void; | ||
private readonly NIL: void; | ||
push<b>(b: b): HList<b, HNil>; | ||
} | ||
class HCons<a, c extends HNil | HList<any, any>> { | ||
private CONS: a; | ||
private readonly CONS: a; | ||
push<b>(b: b): HList<b, this>; | ||
@@ -416,4 +414,11 @@ head(): a; | ||
export class DataMap<K, V> { | ||
get(key: K): V; | ||
export interface WeakMapLike<K, V> { | ||
delete(key: K): boolean; | ||
get(key: K): V | undefined; | ||
has(key: K): boolean; | ||
set(key: K, value: V): this; | ||
} | ||
export class DataMap<K, V> implements WeakMapLike<K, V> { | ||
constructor(entries?: Iterable<[K, V]>); | ||
get(key: K): V | undefined; | ||
set(key: K, val: V): this; | ||
@@ -425,16 +430,17 @@ has(key: K): boolean; | ||
} | ||
export class AttrMap<O extends Object, K, V> { | ||
get(obj: O, key: K): V; | ||
set(obj: O, key: K, val: V): this; | ||
has(obj: O, key: K): boolean; | ||
delete(obj: O, key?: K): boolean; | ||
export class AttrMap<C, K, V> { | ||
constructor( | ||
entries?: Iterable<[C, K, V]>, | ||
KeyMap?: new <K, V>(entries?: Iterable<[K, V]>) => WeakMapLike<K, V>, | ||
ValueMap?: new <K, V>(entries?: Iterable<[K, V]>) => WeakMapLike<K, V> | ||
); | ||
get(ctx: C, key: K): V | undefined; | ||
set(ctx: C, key: K, val: V): this; | ||
has(ctx: C): boolean; | ||
has(ctx: C, key: K): boolean; | ||
delete(ctx: C): boolean; | ||
delete(ctx: C, key: K): boolean; | ||
} | ||
export class RelationMap<S extends Object, T extends Object, V> { | ||
get(source: S, target: T): V; | ||
set(source: S, target: T, val: V): this; | ||
has(source: S, target: T): boolean; | ||
delete(source: S, target?: T): boolean; | ||
} | ||
export function Mixin<T>(...mixins: Array<new (...args: any[]) => any>): new (...args: any[]) => T; | ||
export function Mixin<T>(...mixins: Array<new () => Object>): new () => T | ||
@@ -441,0 +447,0 @@ export function Tick(fn: (_?: void) => any): void |
@@ -13,3 +13,2 @@ export {Supervisor} from './lib/supervisor'; | ||
export {AttrMap} from './lib/collection/attrmap'; | ||
export {RelationMap} from './lib/collection/relationmap'; | ||
export {Mixin} from './lib/mixin'; | ||
@@ -16,0 +15,0 @@ export {Tick} from './lib/tick'; |
@@ -22,13 +22,13 @@ import {noop} from './noop'; | ||
private reason: L; | ||
public listeners: Set<(reason: L) => void> = new Set(); | ||
public readonly listeners: Set<(reason: L) => void> = new Set(); | ||
public cancel: (reason: L) => void; | ||
public promise = <T>(val: T): Promise<T> => | ||
public readonly promise = <T>(val: T): Promise<T> => | ||
this.canceled | ||
? this.promise_ = this.promise_ || new Promise((_, reject) => void reject(this.reason)) | ||
: Promise.resolve(val); | ||
public maybe = <T>(val: T): Maybe<T> => | ||
public readonly maybe = <T>(val: T): Maybe<T> => | ||
this.canceled | ||
? Nothing | ||
: Just(val); | ||
public either = <R>(val: R): Either<L, R> => | ||
public readonly either = <R>(val: R): Either<L, R> => | ||
this.canceled | ||
@@ -35,0 +35,0 @@ ? Left(this.reason) |
import {AttrMap} from './attrmap'; | ||
import {DataMap} from './datamap'; | ||
describe('Unit: lib/attrmap', () => { | ||
describe('AttrMap', () => { | ||
it('initialize', () => { | ||
const map = new AttrMap<number, number, number>(<[number, number, number][]>[[1, 2, 3]], Map); | ||
assert(map.get(1, 2) === 3); | ||
}); | ||
it('get/set', () => { | ||
const map = new AttrMap<{}, number, string>(); | ||
const o1 = {}; | ||
const o2 = {}; | ||
assert(map.get(o1, 0) === void 0); | ||
map.set(o1, 0, ''); | ||
assert(map.get(o1, 0) === ''); | ||
assert(map.get(o2, 0) === void 0); | ||
map.set(o2, 0, ' '); | ||
assert(map.get(o2, 0) === ' '); | ||
assert(map.get(o1, 0) === ''); | ||
map.set(o1, 0, ' '); | ||
assert(map.get(o1, 0) === ' '); | ||
const map = new AttrMap<number, number, string>([], Map); | ||
assert(map.get(0, 0) === void 0); | ||
map.set(0, 0, ''); | ||
assert(map.get(0, 0) === ''); | ||
assert(map.get(1, 0) === void 0); | ||
map.set(1, 0, ' '); | ||
assert(map.get(1, 0) === ' '); | ||
assert(map.get(0, 0) === ''); | ||
map.set(0, 0, ' '); | ||
assert(map.get(0, 0) === ' '); | ||
}); | ||
it('has', () => { | ||
const map = new AttrMap<{}, number, string>(); | ||
const o1 = {}; | ||
const o2 = {}; | ||
assert(map.has(o1, 0) === false); | ||
map.set(o1, 0, ''); | ||
assert(map.has(o1, 0) === true); | ||
assert(map.has(o2, 0) === false); | ||
assert.deepStrictEqual(Object.keys(o1), []); | ||
assert.deepStrictEqual(Object.keys(o2), []); | ||
const map = new AttrMap<{}, number, string>([], Map); | ||
assert(map.has(0, 0) === false); | ||
map.set(0, 0, ''); | ||
assert(map.has(0, 0) === true); | ||
assert(map.has(1, 0) === false); | ||
}); | ||
it('delete', () => { | ||
const map = new AttrMap<{}, number, string>(); | ||
const o1 = {}; | ||
map.set(o1, 0, ''); | ||
assert(map.delete(o1, 0) === true); | ||
assert(map.has(o1, 0) === false); | ||
assert(map.delete(o1, 0) === false); | ||
assert(map.delete(o1) === true); | ||
assert(map.has(o1, 0) === false); | ||
assert(map.delete(o1) === false); | ||
const map = new AttrMap<{}, number, string>([], Map); | ||
map.set(0, 0, ''); | ||
assert(map.delete(0, 0) === true); | ||
assert(map.has(0, 0) === false); | ||
assert(map.delete(0, 0) === false); | ||
assert(map.delete(0) === true); | ||
assert(map.has(0, 0) === false); | ||
assert(map.delete(0) === false); | ||
}); | ||
it('injection', () => { | ||
const map = new AttrMap<{}, number[], number>([], DataMap, DataMap); | ||
map.set({}, [0], 0); | ||
assert(map.get({}, [0]) === 0); | ||
}); | ||
}); | ||
}); |
@@ -1,23 +0,40 @@ | ||
export class AttrMap<O extends Object, K, V> { | ||
private store = new WeakMap<O, Map<K, V>>(); | ||
public get(obj: O, key: K): V { | ||
return this.store.get(obj)! && this.store.get(obj)!.get(key)!; | ||
import {WeakMapLike} from 'spica'; | ||
export class AttrMap<C, K, V> { | ||
constructor( | ||
entries: Iterable<[C, K, V]> = [], | ||
private readonly KeyMap: new <K, V>(entries?: Iterable<[K, V]>) => WeakMapLike<K, V> = WeakMap, | ||
private readonly ValueMap: new <K, V>(entries?: Iterable<[K, V]>) => WeakMapLike<K, V> = Map | ||
) { | ||
void Array.from(entries) | ||
.forEach(([c, k, v]) => | ||
void this.set(c, k, v)); | ||
} | ||
public set(obj: O, key: K, val: V): this { | ||
const store = this.store.has(obj) | ||
? this.store.get(obj)! | ||
: this.store.set(obj, new Map<K, V>()).get(obj)!; | ||
private readonly store = new this.KeyMap<C, WeakMapLike<K, V>>(); | ||
public get(ctx: C, key: K): V | undefined { | ||
return this.store.get(ctx) && this.store.get(ctx)!.get(key)!; | ||
} | ||
public set(ctx: C, key: K, val: V): this { | ||
const store = this.store.has(ctx) | ||
? this.store.get(ctx)! | ||
: this.store.set(ctx, new this.ValueMap<K, V>()).get(ctx)!; | ||
void store.set(key, val); | ||
return this; | ||
} | ||
public has(obj: O, key: K): boolean { | ||
return this.store.has(obj) && this.store.get(obj)!.has(key); | ||
public has(ctx: C): boolean | ||
public has(ctx: C, key: K): boolean | ||
public has(ctx: C, key?: K): boolean { | ||
return arguments.length === 1 | ||
? this.store.has(ctx) | ||
: this.store.has(ctx) && this.store.get(ctx)!.has(key!); | ||
} | ||
public delete(obj: O, key?: K): boolean { | ||
return key === void 0 | ||
? this.store.delete(obj) | ||
: this.store.has(obj) | ||
? this.store.get(obj)!.delete(key) | ||
public delete(ctx: C): boolean | ||
public delete(ctx: C, key: K): boolean | ||
public delete(ctx: C, key?: K): boolean { | ||
return arguments.length === 1 | ||
? this.store.delete(ctx) | ||
: this.store.has(ctx) | ||
? this.store.get(ctx)!.delete(key!) | ||
: false; | ||
} | ||
} |
@@ -5,2 +5,7 @@ import {DataMap} from './datamap'; | ||
describe('DataMap', () => { | ||
it('initialize', () => { | ||
const map = new DataMap<{}, number>(<[{}, number][]>[[{}, 1]]); | ||
assert(map.get({}) === 1); | ||
}); | ||
it('get/set', () => { | ||
@@ -7,0 +12,0 @@ const map = new DataMap<Array<string | Array<string>> | {}, string>(); |
@@ -0,1 +1,2 @@ | ||
import {WeakMapLike} from 'spica'; | ||
import {sqid} from '../sqid'; | ||
@@ -8,5 +9,10 @@ import {type} from '../type'; | ||
export class DataMap<K, V> { | ||
private store = new Map<string, [K, V]>(); | ||
private weakstore = new WeakMap<K, string>(); | ||
export class DataMap<K, V> implements WeakMapLike<K, V> { | ||
constructor(entries: Iterable<[K, V]> = []) { | ||
void Array.from(entries) | ||
.forEach(([k, v]) => | ||
void this.set(k, v)); | ||
} | ||
private readonly store = new Map<string, [K, V]>(); | ||
private readonly weakstore = new WeakMap<K, string>(); | ||
private stringify(key: any): string { | ||
@@ -27,9 +33,9 @@ switch (typeof key) { | ||
if (Array.isArray(key)) { | ||
return `9:[ ${this.stringifyArray(<any[]>key)} ]`; | ||
return `9:[ ${this.stringifyArray(key)} ]`; | ||
} | ||
return `9:{ ${ | ||
this.weakstore.has(key) | ||
? this.weakstore.get(key) | ||
: this.stringifyObject(key) || this.weakstore.set(key, sqid()) | ||
} }`; | ||
this.stringifyObject(key) || | ||
this.weakstore.get(key)! || | ||
this.weakstore.set(key, sqid()).get(key)! | ||
} }`; | ||
} | ||
@@ -54,3 +60,3 @@ } | ||
} | ||
public get(key: K): V { | ||
public get(key: K): V | undefined { | ||
return (this.store.get(this.stringify(key)) || <[void, V]><any>[])[1]; | ||
@@ -57,0 +63,0 @@ } |
@@ -24,2 +24,3 @@ import {compose} from './compose'; | ||
const x = new X(); | ||
assert(x instanceof X); | ||
assert(X['a'] === 'A'); | ||
@@ -58,2 +59,3 @@ assert(X.x === 'X'); | ||
const x = new X(); | ||
assert(x instanceof X); | ||
assert(X['a'] === 'A'); | ||
@@ -60,0 +62,0 @@ assert(X['b'] === 'B'); |
import {assign} from './assign'; | ||
import {concat} from './concat'; | ||
export function compose<T extends new (...args: any[]) => any>(target: T, ...sources: T[]): T { | ||
return concat([target], sources) | ||
export function compose<T extends new (...args: any[]) => Object>(target: T, ...sources: T[]): T { | ||
return sources | ||
.reduce((b, d) => { | ||
@@ -10,3 +9,4 @@ void assign(b.prototype, d.prototype); | ||
return b; | ||
}); | ||
} | ||
, target); | ||
} |
@@ -1,34 +0,2 @@ | ||
interface Curry { | ||
<z>(f: () => z, ctx?: any): () => z; | ||
<a, z>(f: (a: a) => z, ctx?: any): Curried1<a, z>; | ||
<a, b, z>(f: (a: a, b: b) => z, ctx?: any): Curried2<a, b, z>; | ||
<a, b, c, z>(f: (a: a, b: b, c: c) => z, ctx?: any): Curried3<a, b, c, z>; | ||
<a, b, c, d, z>(f: (a: a, b: b, c: c, d: d) => z, ctx?: any): Curried4<a, b, c, d, z>; | ||
<a, b, c, d, e, z>(f: (a: a, b: b, c: c, d: d, e: e) => z, ctx?: any): Curried5<a, b, c, d, e, z>; | ||
} | ||
export interface Curried1<a, z> { | ||
(a: a): z; | ||
} | ||
export interface Curried2<a, b, z> { | ||
(a: a, b: b): z; | ||
(a: a): Curried1<b, z>; | ||
} | ||
export interface Curried3<a, b, c, z> { | ||
(a: a, b: b, c: c): z; | ||
(a: a, b: b): Curried1<c, z>; | ||
(a: a): Curried2<b, c, z>; | ||
} | ||
export interface Curried4<a, b, c, d, z> { | ||
(a: a, b: b, c: c, d: d): z; | ||
(a: a, b: b, c: c): Curried1<d, z>; | ||
(a: a, b: b): Curried2<c, d, z>; | ||
(a: a): Curried3<b, c, d, z>; | ||
} | ||
export interface Curried5<a, b, c, d, e, z> { | ||
(a: a, b: b, c: c, d: d, e: e): z; | ||
(a: a, b: b, c: c, d: d): Curried1<e, z>; | ||
(a: a, b: b, c: c): Curried2<d, e, z>; | ||
(a: a, b: b): Curried3<c, d, e, z>; | ||
(a: a): Curried4<b, c, d, e, z>; | ||
} | ||
import {Curry} from 'spica'; | ||
@@ -35,0 +3,0 @@ export const curry: Curry = <T>(f: () => T, ctx?: any) => |
@@ -1,2 +0,3 @@ | ||
import {curry, Curried2} from './curry'; | ||
import {Curried2} from 'spica'; | ||
import {curry} from './curry'; | ||
@@ -3,0 +4,0 @@ export function flip<a, b, c>(f: (a: a) => (b: b) => c): Curried2<b, a, c> |
@@ -6,3 +6,3 @@ import {concat} from './concat'; | ||
export class HNil { | ||
private NIL: void; | ||
private readonly NIL: void; | ||
constructor() { | ||
@@ -20,3 +20,3 @@ void this.NIL; | ||
class HCons<a, c extends HNil | HList<any, any>> { | ||
private CONS: a; | ||
private readonly CONS: a; | ||
constructor(private head_: a, private tail_: c) { | ||
@@ -23,0 +23,0 @@ void this.CONS; |
@@ -6,3 +6,3 @@ import {concat} from './concat'; | ||
export class Nil { | ||
private NIL: void; | ||
private readonly NIL: void; | ||
constructor() { | ||
@@ -20,3 +20,3 @@ void this.NIL; | ||
class Cons<a, c extends Nil | List<a, any>> { | ||
private CONS: a; | ||
private readonly CONS: a; | ||
constructor(private head_: a, private tail_: c) { | ||
@@ -23,0 +23,0 @@ void this.CONS; |
@@ -8,5 +8,4 @@ import {Mixin} from './mixin'; | ||
class A { | ||
constructor(n: number) { | ||
constructor() { | ||
assert(++cnt === 1); | ||
assert(n === 0); | ||
} | ||
@@ -20,6 +19,5 @@ static a = 'A'; | ||
class X extends Mixin<A>(A) { | ||
constructor(n: number) { | ||
super(n); | ||
constructor() { | ||
super(); | ||
assert(++cnt === 2); | ||
assert(n === 0); | ||
} | ||
@@ -32,3 +30,3 @@ static x = 'X'; | ||
} | ||
const x = new X(0); | ||
const x = new X(); | ||
assert(x instanceof A === false); | ||
@@ -48,5 +46,4 @@ assert(x instanceof X); | ||
class A { | ||
constructor(n: number) { | ||
constructor() { | ||
assert(++cnt === 1); | ||
assert(n === 0); | ||
} | ||
@@ -60,5 +57,4 @@ static a = 'A'; | ||
class B { | ||
constructor(n: number) { | ||
constructor() { | ||
assert(++cnt === 2); | ||
assert(n === 0); | ||
} | ||
@@ -74,6 +70,5 @@ static b = 'B'; | ||
class X extends Mixin<AB>(B, A) { | ||
constructor(n: number) { | ||
super(n); | ||
constructor() { | ||
super(); | ||
assert(++cnt === 3); | ||
assert(n === 0); | ||
} | ||
@@ -86,3 +81,3 @@ static x = 'X'; | ||
} | ||
const x = new X(0); | ||
const x = new X(); | ||
assert(++cnt === 4); | ||
@@ -106,5 +101,4 @@ assert(x instanceof A === false); | ||
class A { | ||
constructor(n: number) { | ||
constructor() { | ||
assert(++cnt === 1); | ||
assert(n === 0); | ||
} | ||
@@ -118,5 +112,4 @@ static a = 'A'; | ||
class B { | ||
constructor(n: number) { | ||
constructor() { | ||
assert(++cnt === 2); | ||
assert(n === 0); | ||
} | ||
@@ -130,5 +123,4 @@ static b = 'B'; | ||
class C { | ||
constructor(n: number) { | ||
constructor() { | ||
assert(++cnt === 3); | ||
assert(n === 0); | ||
} | ||
@@ -144,4 +136,4 @@ static c = 'C'; | ||
class X extends Mixin<ABC>(C, B, A) { | ||
constructor(n: number) { | ||
super(n); | ||
constructor() { | ||
super(); | ||
assert(++cnt === 4); | ||
@@ -155,3 +147,3 @@ } | ||
} | ||
const x = new X(0); | ||
const x = new X(); | ||
assert(++cnt === 5); | ||
@@ -158,0 +150,0 @@ assert(x instanceof A === false); |
import {assign} from './assign'; | ||
export function Mixin<T>(...mixins: Array<new (...args: any[]) => any>): new (...args: any[]) => T { | ||
return mixins.reduceRight((b, d) => __extends(d, b), class { }); | ||
export function Mixin<T>(...mixins: Array<new () => Object>): new () => T { | ||
return <new () => T>mixins.reduceRight((b, d) => __extends(d, b), class { }); | ||
} | ||
function __extends(d: new () => any, b: new () => any): new () => any { | ||
function __extends(d: new () => Object, b: new () => Object): new () => Object { | ||
const __ = class { | ||
constructor() { | ||
return d.apply(b.apply(this, arguments) || this, arguments); | ||
return d.call(b.call(this) || this); | ||
} | ||
@@ -12,0 +12,0 @@ }; |
@@ -13,7 +13,11 @@ import {Functor} from './functor'; | ||
export function ap<a, b>(af: Applicative<(a: a) => b>): (aa: Applicative<a>) => Applicative<b>; | ||
export function ap<a, b>(af: Applicative<(a: a) => b>, aa?: Applicative<a>): Applicative<b> | ((fa: Applicative<a>) => Applicative<b>) { | ||
export function ap<a, b>(af: Applicative<(a: a) => b>, aa?: Applicative<a>): Applicative<b> | ((aa: Applicative<a>) => Applicative<b>) { | ||
return aa | ||
? af.bind(f => aa.fmap(a => f.length === 0 ? f(a) : curry(f)(a))) | ||
: (aa: Applicative<a>) => af.bind(f => aa.fmap(a => f.length === 0 ? f(a) : curry(f)(a))); | ||
? af.bind(f => | ||
aa.fmap(a => | ||
f.length === 0 | ||
? f(a) | ||
: curry(f)(a))) | ||
: (aa: Applicative<a>) => ap(af, aa); | ||
} | ||
} |
import {Monad} from './monad'; | ||
export class Either<a, b> extends Monad<b> { | ||
protected EITHER: Left<a> | Right<b>; | ||
private readonly EITHER: Left<a> | Right<b>; | ||
constructor(thunk: () => Either<a, b>) { | ||
super(thunk); | ||
void this.EITHER; | ||
} | ||
@@ -59,6 +60,6 @@ public fmap<c>(f: (b: b) => c): Either<a, c> { | ||
export class Left<a> extends Either<a, any> { | ||
protected EITHER: Left<a>; | ||
protected LEFT: a; | ||
private readonly LEFT: a; | ||
constructor(private a: a) { | ||
super(throwCallError); | ||
void this.LEFT; | ||
} | ||
@@ -80,6 +81,6 @@ public bind(_: (b: any) => Left<a>): Left<a> | ||
export class Right<b> extends Either<any, b> { | ||
protected EITHER: Right<b>; | ||
protected RIGHT: b; | ||
constructor(private b: b) { | ||
private readonly RIGHT: b; | ||
constructor(private readonly b: b) { | ||
super(throwCallError); | ||
void this.RIGHT; | ||
} | ||
@@ -86,0 +87,0 @@ public bind<c>(f: (b: b) => Right<c>): Right<c> |
export abstract class Lazy<a> { | ||
constructor(protected thunk: () => Lazy<a>) { | ||
constructor(protected readonly thunk: () => Lazy<a>) { | ||
} | ||
@@ -8,2 +8,3 @@ private memory_: this; | ||
} | ||
public abstract extract(): any; | ||
} |
import {MonadPlus} from './monadplus'; | ||
export class Maybe<a> extends MonadPlus<a> { | ||
protected MAYBE: Just<a> | Nothing; | ||
private readonly MAYBE: Just<a> | Nothing; | ||
constructor(thunk: () => Maybe<a>) { | ||
super(thunk); | ||
void this.MAYBE; | ||
} | ||
@@ -63,6 +64,6 @@ public fmap<b>(f: (a: a) => b): Maybe<b> { | ||
export class Just<a> extends Maybe<a> { | ||
protected MAYBE: Just<a>; | ||
protected JUST: a; | ||
constructor(private a: a) { | ||
private readonly JUST: a; | ||
constructor(private readonly a: a) { | ||
super(throwCallError); | ||
void this.JUST; | ||
} | ||
@@ -85,6 +86,6 @@ public bind(f: (a: a) => Nothing): Maybe<a> | ||
export class Nothing extends Maybe<any> { | ||
protected MAYBE: Nothing; | ||
protected NOTHING: void; | ||
private readonly NOTHING: void; | ||
constructor() { | ||
super(throwCallError); | ||
void this.NOTHING; | ||
} | ||
@@ -91,0 +92,0 @@ public bind(f: (a: any) => Nothing): Nothing |
@@ -13,4 +13,4 @@ import {Applicative} from './applicative'; | ||
? m.bind(f) | ||
: (f: (a: a) => Monad<b>) => m.bind(f); | ||
: (f: (a: a) => Monad<b>) => bind(m, f); | ||
} | ||
} |
import {Sequence} from './sequence'; | ||
describe('Unit: lib/monad/sequence', () => { | ||
describe('Iterable', () => { | ||
it('idempotence', () => { | ||
const s = Sequence.from([0, 1, 2]); | ||
assert.deepStrictEqual(Array.from(s), [0, 1, 2]); | ||
assert.deepStrictEqual(Array.from(s), [0, 1, 2]); | ||
assert.deepStrictEqual(Sequence.from(s).extract(), [0, 1, 2]); | ||
assert.deepStrictEqual(Sequence.from(s).extract(), [0, 1, 2]); | ||
assert.deepStrictEqual(Array.from(s), [0, 1, 2]); | ||
assert.deepStrictEqual(Sequence.from(s).extract(), [0, 1, 2]); | ||
}); | ||
it('to Sequence', () => { | ||
assert.deepStrictEqual(Sequence.from(Sequence.from([])).extract(), []); | ||
assert.deepStrictEqual(Sequence.from(Sequence.from([0])).extract(), [0]); | ||
assert.deepStrictEqual(Sequence.from(Sequence.from([0, 1])).extract(), [0, 1]); | ||
assert.deepStrictEqual(Sequence.from(Sequence.from([0, 1, 2])).extract(), [0, 1, 2]); | ||
}); | ||
it('to Array', () => { | ||
assert.deepStrictEqual(Array.from(Sequence.from([])), []); | ||
assert.deepStrictEqual(Array.from(Sequence.from([0])), [0]); | ||
assert.deepStrictEqual(Array.from(Sequence.from([0, 1])), [0, 1]); | ||
assert.deepStrictEqual(Array.from(Sequence.from([0, 1, 2])), [0, 1, 2]); | ||
}); | ||
}); | ||
describe('Monoid', () => { | ||
@@ -5,0 +32,0 @@ it('Monoid law 1', () => { |
import {Sequence} from './sequence/core'; | ||
import resume from './sequence/member/static/resume'; | ||
import from from './sequence/member/static/from'; | ||
import read from './sequence/member/static/read'; | ||
import cycle from './sequence/member/static/cycle'; | ||
@@ -42,7 +41,6 @@ import random from './sequence/member/static/random'; | ||
compose( | ||
void compose( | ||
Sequence, | ||
resume, | ||
from, | ||
read, | ||
cycle, | ||
@@ -49,0 +47,0 @@ random, |
@@ -0,18 +1,33 @@ | ||
import {Sequence as ISequence} from 'spica'; | ||
import {MonadPlus} from '../monadplus'; | ||
export class Sequence<a, z> extends MonadPlus<a> { | ||
type ESIterator<T> = Iterator<T>; | ||
export class Sequence<a, z> extends MonadPlus<a> implements Iterable<a> { | ||
constructor( | ||
protected cons: (z: z, cons: (a?: a, z?: z) => Sequence.Data<a, z>) => Sequence.Data<a, z>, | ||
protected memory?: Map<number, Sequence.Data<a, z>> | ||
protected readonly cons: (z: z, cons: (a?: a, z?: z) => Sequence.Data<a, z>) => Sequence.Data<a, z>, | ||
protected readonly memory?: Map<number, Sequence.Data<a, z>> | ||
) { | ||
super(throwCallError); | ||
} | ||
public [Symbol.iterator](): Iterator<a> { | ||
let iter = () => this.iterate(); | ||
return { | ||
next() { | ||
const thunk = iter(); | ||
iter = Sequence.Thunk.iterator(thunk); | ||
return { | ||
done: !Sequence.isIterable(thunk), | ||
value: Sequence.Thunk.value(thunk) | ||
}; | ||
} | ||
}; | ||
} | ||
} | ||
export namespace Sequence { | ||
export declare function resume<a>(iterator: Sequence.Iterator<a>): Sequence<a, Sequence.Iterator<a>>; | ||
export declare function from<a>(as: a[]): Sequence<a, number>; | ||
export declare function read<a>(as: a[]): Sequence<a, a[]>; | ||
export declare function cycle<a>(as: a[]): Sequence<a, number>; | ||
export declare function random(): Sequence<number, number>; | ||
export declare function random<a>(gen: () => a): Sequence<a, number>; | ||
export declare function from<a>(as: Iterable<a>): Sequence<a, [ESIterator<a>, number, Map<number, IteratorResult<a>>]>; | ||
export declare function cycle<a>(as: Iterable<a>): Sequence<a, [ESIterator<a>, number, Map<number, IteratorResult<a>>]>; | ||
export declare function random(): Sequence<number, [ESIterator<number>, number, Map<number, IteratorResult<number>>]>; | ||
export declare function random<a>(gen: () => a): Sequence<a, [ESIterator<a>, number, Map<number, IteratorResult<a>>]>; | ||
export declare function random<a>(as: a[]): Sequence<a, Sequence.Iterator<number>>; | ||
@@ -34,3 +49,3 @@ export declare function concat<a>(as: Sequence<Sequence<a, any>, any>): Sequence<a, [Sequence.Iterator<Sequence<a, any>>, Sequence.Iterator<a>]>; | ||
export declare function mappend<a>(l: Sequence<a, any>, r: Sequence<a, any>): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]>; | ||
export declare function mconcat<a>(as: Sequence<a, any>[]): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]>; | ||
export declare function mconcat<a>(as: Iterable<Sequence<a, any>>): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]>; | ||
export declare const mzero: Sequence<any, any>; | ||
@@ -41,2 +56,3 @@ export declare function mplus<a>(l: Sequence<a, any>, r: Sequence<a, any>): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]>; | ||
extract(): a[]; | ||
[Symbol.iterator](): Iterator<a>; | ||
iterate(): Sequence.Thunk<a>; | ||
@@ -69,5 +85,5 @@ fmap<b>(f: (a: a) => b): Sequence<b, Sequence.Iterator<a>>; | ||
export namespace Sequence { | ||
export type Data<a, z> = [a, z]; | ||
export type Data<a, z> = ISequence.Data<a, z>; | ||
export namespace Data { | ||
export function cons<a, z>(a?: a, b?: z): Sequence.Data<a, z> { | ||
export function cons<a, z>(a?: a, z?: z): Sequence.Data<a, z> { | ||
switch (arguments.length) { | ||
@@ -79,3 +95,3 @@ case 0: | ||
case 2: | ||
return <Sequence.Data<a, z>>[a, b]; | ||
return <Sequence.Data<a, z>>[a, z]; | ||
default: | ||
@@ -86,3 +102,3 @@ throw Sequence.Exception.invalidConsError(arguments); | ||
} | ||
export type Thunk<a> = [a, Iterator<a>, number]; | ||
export type Thunk<a> = ISequence.Thunk<a>; | ||
export namespace Thunk { | ||
@@ -99,3 +115,3 @@ export function value<a>(thunk: Thunk<a>): a { | ||
} | ||
export type Iterator<a> = () => Thunk<a>; | ||
export type Iterator<a> = ISequence.Iterator<a>; | ||
export namespace Iterator { | ||
@@ -102,0 +118,0 @@ export let /* const */ done: Sequence.Iterator<any> = () => <Sequence.Thunk<any>>[void 0, done, -1]; |
@@ -5,16 +5,13 @@ import {Sequence} from '../../../sequence'; | ||
describe('memoize', () => { | ||
it('read unmemoized', () => { | ||
const seq = Sequence.read([0, 1, 2]); | ||
assert.deepStrictEqual(seq.extract(), [0, 1, 2]); | ||
assert.deepStrictEqual(seq.extract(), []); | ||
it('side effects', () => { | ||
let cnt = 0; | ||
const mem = Sequence.cycle([() => ++cnt]) | ||
.map(f => f()) | ||
.memoize(); | ||
assert.deepStrictEqual(mem.take(2).extract(), [1, 2]); | ||
assert.deepStrictEqual(mem.take(2).extract(), [1, 2]); | ||
}); | ||
it('read memoized', () => { | ||
const mem = Sequence.read([0, 1, 2]).memoize(); | ||
assert.deepStrictEqual(mem.extract(), [0, 1, 2]); | ||
assert.deepStrictEqual(mem.extract(), [0, 1, 2]); | ||
}); | ||
}); | ||
}); |
import {Sequence} from '../../../sequence'; | ||
import {sqid} from '../../../../sqid'; | ||
describe('Unit: lib/monad/sequence/member/static/cycle', () => { | ||
describe('Sequence.cycle', () => { | ||
it('array', () => { | ||
it('side effect', () => { | ||
const s = Sequence.cycle(Sequence.random(sqid).take(2)).take(5); | ||
assert(s.extract().length === 5); | ||
assert.notDeepStrictEqual( | ||
s.extract(), | ||
s.extract()); | ||
}); | ||
it('idempotence', () => { | ||
assert.deepStrictEqual( | ||
Sequence.cycle([]) | ||
Sequence.cycle([1]) | ||
.take(2) | ||
.fold((a, b) => Sequence.from([a].concat(b.extract()).concat(b.extract())), Sequence.from<number>([0])) | ||
.extract(), | ||
[]); | ||
[1, 1, 0, 0, 1, 0, 0]); | ||
}); | ||
it('array', () => { | ||
assert.deepStrictEqual( | ||
@@ -11,0 +25,0 @@ Sequence.cycle([0]) |
import {Sequence} from '../../core'; | ||
export default class <a, z> extends Sequence<a, z> { | ||
public static cycle<a>(as: a[]): Sequence<a, number> { | ||
return new Sequence<a, number>((i = 0, cons) => | ||
as.length === 0 | ||
? cons() | ||
: cons(as[i], ++i % as.length)); | ||
public static cycle<a>(as: Iterable<a>): Sequence<a, [Iterator<a>, number, Map<number, IteratorResult<a>>]> { | ||
return new Sequence<a, [Iterator<a>, number, Map<number, IteratorResult<a>>]>( | ||
function cycle( | ||
[iter, i, cache] = [as[Symbol.iterator](), 0, new Map<number, IteratorResult<a>>()], | ||
cons) | ||
: Sequence.Data<a, [Iterator<a>, number, Map<number, IteratorResult<a>>]> { | ||
const result = cache.has(i) | ||
? cache.get(i)! | ||
: cache.set(i, iter.next()).get(i)!; | ||
return result.done | ||
? cycle([as[Symbol.iterator](), i + 1, cache], cons) | ||
: cons(result.value, [iter, i + 1, cache]); | ||
}); | ||
} | ||
} |
import {Sequence} from '../../../sequence'; | ||
import {sqid} from '../../../../sqid'; | ||
describe('Unit: lib/monad/sequence/member/static/from', () => { | ||
describe('Sequence.from', () => { | ||
it('side effect', () => { | ||
const s = Sequence.from(Sequence.random(sqid)).take(5); | ||
assert(s.extract().length === 5); | ||
assert.notDeepStrictEqual( | ||
s.extract(), | ||
s.extract()); | ||
}); | ||
it('idempotence', () => { | ||
assert.deepStrictEqual( | ||
Sequence.from([0, 1]) | ||
.fold((a, b) => Sequence.from([a].concat(b.extract()).concat(b.extract())), Sequence.from<number>([])) | ||
.extract(), | ||
[0, 1, 1]); | ||
}); | ||
it('array', () => { | ||
@@ -6,0 +23,0 @@ assert.deepStrictEqual( |
import {Sequence} from '../../core'; | ||
export default class <a, z> extends Sequence<a, z> { | ||
public static from<a>(as: a[]): Sequence<a, number> { | ||
return new Sequence<a, number>((i = 0, cons) => | ||
i < as.length | ||
? cons(as[i], ++i) | ||
: cons()); | ||
public static from<a>(as: Iterable<a>): Sequence<a, [Iterator<a>, number, Map<number, IteratorResult<a>>]> { | ||
return new Sequence<a, [Iterator<a>, number, Map<number, IteratorResult<a>>]>( | ||
([iter, i, cache] = [as[Symbol.iterator](), 0, new Map<number, IteratorResult<a>>()], cons) => { | ||
const result = cache.has(i) | ||
? cache.get(i)! | ||
: cache.set(i, iter.next()).get(i)!; | ||
return result.done | ||
? cons() | ||
: cons(result.value, [iter, i + 1, cache]); | ||
}); | ||
} | ||
} |
import {Sequence} from '../../core'; | ||
export default class <a, z> extends Sequence<a, z> { | ||
public static mconcat<a>(as: Sequence<a, any>[]): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]> { | ||
return as.reduce((a, b) => mconcat(a, b), Sequence.mempty); | ||
public static mconcat<a>(as: Iterable<Sequence<a, any>>): Sequence<a, [Sequence.Iterator<a>, Sequence.Iterator<a>]> { | ||
return Array.from(as) | ||
.reduce((a, b) => mconcat(a, b), Sequence.mempty); | ||
} | ||
@@ -7,0 +8,0 @@ } |
import {Sequence} from '../../../sequence'; | ||
import {sqid} from '../../../../sqid'; | ||
describe('Unit: lib/monad/sequence/member/static/random', () => { | ||
describe('Sequence.random', () => { | ||
it('validate', () => { | ||
assert.deepStrictEqual( | ||
Sequence.random(sqid) | ||
.take(5) | ||
.subsequences() | ||
.filter(ns => ns.length === 2) | ||
.extract() | ||
.reduce((cnt, [n, m]) => n !== m ? ++cnt : cnt, 0), | ||
10); | ||
assert.notDeepStrictEqual( | ||
Sequence.random() | ||
.take(9) | ||
.extract(), | ||
Sequence.random() | ||
.take(9) | ||
.extract()); | ||
}); | ||
it('number', () => { | ||
@@ -6,0 +26,0 @@ assert.deepStrictEqual( |
import {Sequence} from '../../core'; | ||
export default class <a, z> extends Sequence<a, z> { | ||
public static random(): Sequence<number, number> | ||
public static random<a>(gen: () => a): Sequence<a, number> | ||
public static random(): Sequence<number, [Iterator<number>, number, Map<number, IteratorResult<number>>]> | ||
public static random<a>(gen: () => a): Sequence<a, [Iterator<a>, number, Map<number, IteratorResult<a>>]> | ||
public static random<a>(as: a[]): Sequence<a, Sequence.Iterator<number>> | ||
public static random<a>(p: (() => number) | (() => a) | a[] = () => Math.random()): Sequence<number, number> | Sequence<a, number> | Sequence<a, Sequence.Iterator<number>> { | ||
switch (true) { | ||
case Array.isArray(p): | ||
return this.random() | ||
.map(r => p[r * p.length | 0]); | ||
default: | ||
return new Sequence<a, number>((_, cons) => cons((<() => a>p)(), NaN)); | ||
} | ||
public static random<a>(p: (() => number) | (() => a) | a[] = () => Math.random()): Sequence<number | a, [Iterator<number | a>, number, Map<number, IteratorResult<number | a>>]> | Sequence<a, Sequence.Iterator<number>> { | ||
return typeof p === 'function' | ||
? Sequence.from(new Sequence<number | a, void>((_, cons) => cons(p(), _))) | ||
: this.random().map(r => p[r * p.length | 0]); | ||
} | ||
} |
@@ -9,4 +9,4 @@ import {Sequence} from '../../core'; | ||
() => cons(), | ||
at => cons(Sequence.Thunk.value(at), Sequence.Thunk.iterator(at)))); | ||
thunk => cons(Sequence.Thunk.value(thunk), Sequence.Thunk.iterator(thunk)))); | ||
} | ||
} |
@@ -9,2 +9,3 @@ import {sqid} from './sqid'; | ||
assert(typeof sqid(1) === 'string'); | ||
assert(typeof sqid(1e14) === 'string'); | ||
}); | ||
@@ -16,4 +17,12 @@ | ||
assert(/^[0-9]{15}$/.test(sqid(1))); | ||
assert(/^[0-9]{15}$/.test(sqid(1e14))); | ||
}); | ||
it('validation', () => { | ||
assert.throws(() => sqid(<any>void 0)); | ||
assert.throws(() => sqid(NaN)); | ||
assert.throws(() => sqid(-1)); | ||
assert.throws(() => sqid(0.1)); | ||
}); | ||
it('inequality', () => { | ||
@@ -26,2 +35,3 @@ assert(sqid() !== sqid()); | ||
assert(sqid(1) === '000000000000001'); | ||
assert(sqid(1e14) === '100000000000000'); | ||
}); | ||
@@ -28,0 +38,0 @@ |
@@ -6,2 +6,7 @@ let cnt = 0; | ||
export function sqid(id?: number): string { | ||
if (arguments.length > 0) { | ||
if (typeof id !== 'number') throw new TypeError(`Spica: sqid: A parameter value must be a number: ${id}`); | ||
if (id >= 0 === false) throw new TypeError(`Spica: sqid: A parameter value must be a positive number: ${id}`); | ||
if (id % 1 !== 0) throw new TypeError(`Spica: sqid: A parameter value must be an integer: ${id}`); | ||
} | ||
return id === void 0 | ||
@@ -8,0 +13,0 @@ ? (1e15 + ++cnt + '').slice(1) |
@@ -63,8 +63,8 @@ import {Supervisor as ISupervisor, SupervisorSettings} from 'spica'; | ||
} | ||
public name: string; | ||
private deps: DataMap<T, T[]> = new DataMap<T, T[]>(); | ||
private retry: boolean; | ||
private timeout: number; | ||
private destructor_: (reason?: any) => any; | ||
public events = { | ||
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; | ||
public readonly events = { | ||
exec: new Observable<T, Supervisor.Event.Data.Exec<T, D, R>, any>(), | ||
@@ -75,3 +75,3 @@ fail: new Observable<T, Supervisor.Event.Data.Fail<T, D>, any>(), | ||
}; | ||
private procs: Observable<T, WorkerCommand<T, D>, R> = new Observable<T, WorkerCommand<T, D>, R>(); | ||
private readonly procs: Observable<T, WorkerCommand<T, D>, R> = new Observable<T, WorkerCommand<T, D>, R>(); | ||
private alive = true; | ||
@@ -90,3 +90,3 @@ private registerable = true; | ||
} | ||
private workerSharedResource: WorkerSharedResources<T, D, R> = { | ||
private readonly workerSharedResource: WorkerSharedResources<T, D, R> = { | ||
procs: this.procs, | ||
@@ -159,3 +159,3 @@ dependenciesStack: [] | ||
} | ||
private queue: [T, D, (results: R[]) => void, number, number][] = []; | ||
private readonly queue: [T, D, (results: R[]) => void, number, number][] = []; | ||
private drain(target: T = <T><any[]>[]): void { | ||
@@ -198,3 +198,3 @@ const now = Date.now(); | ||
abstract class AbstractCommand { | ||
private WORKER_COMMAND: void; | ||
private readonly WORKER_COMMAND: void; | ||
constructor() { | ||
@@ -205,3 +205,3 @@ void this.WORKER_COMMAND; | ||
export class Self extends AbstractCommand { | ||
private COMMAND: this; | ||
private readonly COMMAND: this; | ||
constructor() { | ||
@@ -213,4 +213,4 @@ super(); | ||
export class Deps<T> extends AbstractCommand { | ||
private COMMAND: this; | ||
constructor(public namespace: T) { | ||
private readonly COMMAND: this; | ||
constructor(public readonly namespace: T) { | ||
super(); | ||
@@ -221,4 +221,4 @@ void this.COMMAND; | ||
export class Call<D> extends AbstractCommand { | ||
private COMMAND: this; | ||
constructor(public data: D) { | ||
private readonly COMMAND: this; | ||
constructor(public readonly data: D) { | ||
super(); | ||
@@ -229,4 +229,4 @@ void this.COMMAND; | ||
export class Exit extends AbstractCommand { | ||
private COMMAND: this; | ||
constructor(public reason: any) { | ||
private readonly COMMAND: this; | ||
constructor(public readonly reason: any) { | ||
super(); | ||
@@ -240,7 +240,7 @@ void this.COMMAND; | ||
constructor( | ||
private sv: Supervisor<T, D, R>, | ||
private sharedResource: WorkerSharedResources<T, D, R>, | ||
public namespace: T, | ||
public process: (data: D) => R, | ||
private dependencies: T[] | ||
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[] | ||
) { | ||
@@ -247,0 +247,0 @@ this.receive = (cmd: WorkerCommand<T, D>) => Worker.prototype.receive.call(this, cmd); // identifier |
@@ -12,3 +12,3 @@ import { | ||
HList, HNil, | ||
DataMap, AttrMap, RelationMap, | ||
DataMap, AttrMap, | ||
Mixin, | ||
@@ -126,3 +126,3 @@ Tick, | ||
describe('Map', function () { | ||
describe('Collection', function () { | ||
it('DataMap', function () { | ||
@@ -136,6 +136,2 @@ assert(typeof DataMap === 'function'); | ||
it('RelationMap', function () { | ||
assert(typeof RelationMap === 'function'); | ||
}); | ||
}); | ||
@@ -142,0 +138,0 @@ |
@@ -28,4 +28,5 @@ { | ||
"src/**/*.ts", | ||
"test/**/*.ts" | ||
"test/**/*.ts", | ||
"benchmark/**/*.ts" | ||
] | ||
} |
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
391550
135
9725
47