Comparing version 0.0.29 to 0.0.30
@@ -1,3 +0,3 @@ | ||
/*! spica v0.0.29 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,r){var i=this;void 0===t&&(t=this.timeout),void 0===r&&(r=c.noop),void this.checkState(),e=o.concat([],e),void this.queue.push([e,n,function(e,n){return void r(n,e)},t,Date.now()]),void this.schedule(),t>0!=!1&&void setTimeout(function(){return i.drain(e)},t)},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[0],e[1]),t=n(void 0);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(c,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(){}return e}(),t=function(e){function n(n){e.call(this),this.namespace=n}return __extends(n,e),n}(n);e.Deps=t;var r=function(e){function n(n){e.call(this),this.data=n}return __extends(n,e),n}(n);e.Call=r;var i=function(e){function n(n){e.call(this),this.reason=n}return __extends(n,e),n}(n);e.Exit=i}(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(),void 0===e)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/monad/applicative",["require","exports","src/lib/monad/functor"],function(e,n,t){"use strict";var r=function(e){function n(){e.apply(this,arguments)}return __extends(n,e),n}(t.Functor);n.Applicative=r;var r;!function(e){function n(e,n){return n?e.bind(function(e){return n.fmap(function(n){return e(n)})}):function(n){return e.bind(function(e){return n.fmap(function(n){return e(n)})})}}e.ap=n}(r=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/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)}}var r=this;n.curry=function(e,n){return void 0===n&&(n=r),0===e.length?function(){return e.call(n)}:t(e,[],n)}}),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.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.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";var r=function(e){function n(n,t){e.call(this),this.cons=n,this.memory=t}return __extends(n,e),n}(t.MonadPlus);n.Sequence=r;var r;!function(e){}(r=n.Sequence||(n.Sequence={}));var r;!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={}))}(r=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/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){var u=void 0===i?[function(){return r.iterate()},0]:i,o=u[0];u[1];return t.Sequence.Iterator.when(o(),function(e){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=(t.Sequence.resume(t.Sequence.Thunk.iterator(n)),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/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,P,E,R,D,N,z,A,C,L,F){"use strict";n.Sequence=t.Sequence,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,P.default,E.default,R.default,D.default,N.default,z.default,A.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(){}return e.prototype.push=function(e){return new i(e,this)},e}();n.Nil=r;var i=function(){function e(e,n){this.head_=e,this.tail_=n}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.array=function(){return t.concat([this.head()],this.tail().array?this.tail().array():[])},e}()}),define("src/lib/hlist",["require","exports"],function(e,n){"use strict";var t=function(){function e(){}return e.prototype.push=function(e){return new r(e,this)},e}();n.HNil=t;var r=function(){function e(e,n){this.head_=e,this.tail_=n}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}()}),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=x.concat,n.sort=_.sort}),define("spica",["require","exports","src/export"],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.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)}); |
@@ -18,3 +18,2 @@ const gulp = require('gulp'); | ||
src: [ | ||
'typings/*.d.ts', | ||
'*.ts' | ||
@@ -26,3 +25,2 @@ ], | ||
src: [ | ||
'typings/*.d.ts', | ||
'*.ts', | ||
@@ -98,2 +96,5 @@ 'src/**/*.ts', | ||
.pipe($.typescript(config.ts.options)) | ||
.once("error", function () { | ||
this.once("finish", () => process.exit(1)); | ||
}) | ||
.pipe($.header(config.exporter)) | ||
@@ -166,3 +167,2 @@ .pipe(gulp.dest(config.ts.bench.dest)); | ||
shell('npm i'); | ||
shell('tsd install --save --overwrite'); | ||
}); | ||
@@ -173,3 +173,2 @@ | ||
shell('npm i'); | ||
//shell('tsd update --save --overwrite'); | ||
}); | ||
@@ -176,0 +175,0 @@ |
@@ -1,2 +0,2 @@ | ||
import './typings/spica'; | ||
import './spica.d'; | ||
export * from 'spica'; |
module.exports = function (config) { | ||
config.set({ | ||
basePath: '', | ||
client: { | ||
useIframe: false | ||
}, | ||
frameworks: ['mocha'], | ||
files: [ | ||
{ pattern: 'https://cdn.polyfill.io/v2/polyfill.js', watched: false, served: false, included: true }, | ||
{ pattern: 'https://cdn.polyfill.io/v2/polyfill.js?features=default,WeakMap,WeakSet', watched: false, served: false, included: true }, | ||
{ pattern: 'node_modules/power-assert/build/power-assert.js', watched: true, served: true, included: true }, | ||
@@ -36,5 +33,4 @@ { pattern: 'node_modules/lodash/lodash.js', watched: true, served: true, included: true }, | ||
autoWatchBatchDelay: 500, | ||
browsers: ['Chrome'], | ||
browserNoActivityTimeout: 100 * 1e3 | ||
browsers: ['Chrome'] | ||
}); | ||
}; |
{ | ||
"name": "spica", | ||
"version": "0.0.29", | ||
"version": "0.0.30", | ||
"description": "Supervisor, Observable, Sequence, Maybe, Either and some utils.", | ||
@@ -37,2 +37,5 @@ "private": false, | ||
"devDependencies": { | ||
"@types/benchmark": "^1.0.29", | ||
"@types/mocha": "^2.2.31", | ||
"@types/power-assert": "0.0.27", | ||
"benchmark": "^2.1.1", | ||
@@ -42,3 +45,2 @@ "del": "^2.2.2", | ||
"gulp": "^3.9.1", | ||
"gulp-footer": "^1.0.5", | ||
"gulp-header": "1.8.8", | ||
@@ -63,4 +65,3 @@ "gulp-load-plugins": "^1.2.4", | ||
"run-sequence": "^1.2.2", | ||
"tsd": "^0.6.5", | ||
"typescript": "^1.8.10" | ||
"typescript": "2.1.0-dev.20160829" | ||
}, | ||
@@ -67,0 +68,0 @@ "scripts": { |
@@ -1,1 +0,2 @@ | ||
export * from './src/export'; | ||
import './src/import'; | ||
export * from './src/export'; |
@@ -6,3 +6,3 @@ import {type} from './type'; | ||
export const clone = template((key, target, source): any => { | ||
export let clone = template((key, target, source): any => { | ||
switch (type(source[key])) { | ||
@@ -18,3 +18,3 @@ case 'Array': | ||
export const extend = template((key, target, source): any => { | ||
export let extend = template((key, target, source): any => { | ||
switch (type(source[key])) { | ||
@@ -21,0 +21,0 @@ case 'Array': |
@@ -12,5 +12,5 @@ import {Cancelable} from './cancelable'; | ||
.then(n => (cancelable.cancel(n), ++n)) | ||
.then(n => NaN) | ||
.then(n => cancelable.promise(NaN)) | ||
.then(n => NaN) | ||
.then(_ => NaN) | ||
.then(_ => cancelable.promise(NaN)) | ||
.then(_ => NaN) | ||
.catch(n => assert(++n === 3) || done()); | ||
@@ -17,0 +17,0 @@ }); |
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); | ||
return this.store.get(obj)! && this.store.get(obj)!.get(key)!; | ||
} | ||
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); | ||
? this.store.get(obj)! | ||
: this.store.set(obj, new Map<K, V>()).get(obj)!; | ||
void store.set(key, val); | ||
@@ -14,3 +14,3 @@ return this; | ||
public has(obj: O, key: K): boolean { | ||
return this.store.has(obj) && this.store.get(obj).has(key); | ||
return this.store.has(obj) && this.store.get(obj)!.has(key); | ||
} | ||
@@ -21,5 +21,5 @@ public delete(obj: O, key?: K): boolean { | ||
: this.store.has(obj) | ||
? this.store.get(obj).delete(key) | ||
? this.store.get(obj)!.delete(key) | ||
: false; | ||
} | ||
} |
@@ -53,3 +53,3 @@ import {sqid} from '../sqid'; | ||
public get(key: K): V { | ||
return (this.store.get(this.stringify(key)) || <[void, V]>[])[1]; | ||
return (this.store.get(this.stringify(key)) || <[void, V]><any>[])[1]; | ||
} | ||
@@ -56,0 +56,0 @@ public set(key: K, val: V): this { |
export class RelationMap<S extends Object, T extends Object, V> { | ||
private store = new WeakMap<S, WeakMap<T, V>>(); | ||
public get(source: S, target: T): V { | ||
return this.store.get(source) && this.store.get(source).get(target); | ||
return this.store.get(source)! && this.store.get(source)!.get(target)!; | ||
} | ||
public set(source: S, target: T, val: V): this { | ||
const store = this.store.has(source) | ||
? this.store.get(source) | ||
: this.store.set(source, new WeakMap<T, V>()).get(source); | ||
? this.store.get(source)! | ||
: this.store.set(source, new WeakMap<T, V>()).get(source)!; | ||
void store.set(target, val); | ||
@@ -14,3 +14,3 @@ return this; | ||
public has(source: S, target: T): boolean { | ||
return this.store.has(source) && this.store.get(source).has(target); | ||
return this.store.has(source) && this.store.get(source)!.has(target); | ||
} | ||
@@ -21,5 +21,5 @@ public delete(source: S, target?: T): boolean { | ||
: this.store.has(source) | ||
? this.store.get(source).delete(target) | ||
? this.store.get(source)!.delete(target) | ||
: false; | ||
} | ||
} |
@@ -35,3 +35,3 @@ interface Curry { | ||
export const curry: Curry = <T>(f: () => T, ctx: any = this) => | ||
export const curry: Curry = <T>(f: () => T, ctx?: any) => | ||
f.length === 0 | ||
@@ -38,0 +38,0 @@ ? () => f.call(ctx) |
@@ -5,6 +5,2 @@ import {HList, HNil} from './hlist'; | ||
describe('HList', () => { | ||
it('HNil', () => { | ||
const nil = new HNil(); | ||
}); | ||
it('HList 1', () => { | ||
@@ -49,4 +45,35 @@ const list: HList<number, HNil> = new HNil().push(0); | ||
it('compact', () => { | ||
{ | ||
const l: HList<number[], HNil> = new HNil().push(1).push([2]).compact((ns, n) => ns.concat(n)); | ||
assert.deepStrictEqual(l.tuple(), [[2, 1]]); | ||
} | ||
{ | ||
const l: HList<number[], HList<string, HNil>> = new HNil().push('').push(2).push([5]).compact((ns, n) => ns.concat(n)); | ||
assert.deepStrictEqual(l.tuple(), [[5, 2], '']); | ||
} | ||
}); | ||
it('reverse', () => { | ||
const t: [boolean, number, string] = new HNil().push(false).push(0).push('').reverse().tuple(); | ||
assert.deepStrictEqual(t, [false, 0, '']); | ||
}); | ||
it('tuple', () => { | ||
{ | ||
const t: [boolean] = new HNil().push(false).tuple(); | ||
assert.deepStrictEqual(t, [false]); | ||
} | ||
{ | ||
const t: [number, boolean] = new HNil().push(false).push(0).tuple(); | ||
assert.deepStrictEqual(t, [0, false]); | ||
} | ||
{ | ||
const t: [string, number, boolean] = new HNil().push(false).push(0).push('').tuple(); | ||
assert.deepStrictEqual(t, ['', 0, false]); | ||
} | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
import {concat} from './concat'; | ||
export interface HList<a, c extends HNil | HList<any, any>> extends HCons<a, c> { } | ||
@@ -5,12 +7,19 @@ | ||
private NIL: void; | ||
public push<b>(b: b): HCons<b, HNil> { | ||
constructor() { | ||
void this.NIL; | ||
} | ||
public push<b>(b: b): HList<b, HNil> { | ||
return new HCons<b, HNil>(b, this); | ||
} | ||
public array(): never[] { | ||
return []; | ||
} | ||
} | ||
class HCons<a, c extends HNil | HCons<any, any>> { | ||
class HCons<a, c extends HNil | HList<any, any>> { | ||
private CONS: a; | ||
constructor(private head_: a, private tail_: c) { | ||
void this.CONS; | ||
} | ||
public push<b>(b: b): HCons<b, this> { | ||
public push<b>(b: b): HList<b, this> { | ||
return new HCons<b, this>(b, this); | ||
@@ -28,8 +37,39 @@ } | ||
} | ||
public modify<b>(f: (a: a) => b): HCons<b, c> { | ||
public modify<b>(f: (a: a) => b): HList<b, c> { | ||
return (<any>this.tail().push)(f(this.head())); | ||
} | ||
public extend<b>(f: (a: a) => b): HCons<b, this> { | ||
public extend<b>(f: (a: a) => b): HList<b, this> { | ||
return this.push(f(this.head())); | ||
} | ||
public compact<b, c, d extends HNil | HList<any, any>>(this: HList<a, HList<b, d>>, f: (a: a, b: b) => c): HList<c, d> { | ||
return this.tail().modify(r => f(this.head(), r)); | ||
} | ||
public reverse<a>(this: HList<a, HNil>): HList<a, HNil> | ||
public reverse<a, b>(this: HList<a, HList<b, HNil>>): HList<b, HList<a, HNil>> | ||
public reverse<a, b, c>(this: HList<a, HList<b, HList<c, HNil>>>): HList<c, HList<b, HList<a, HNil>>> | ||
public reverse<a, b, c, d>(this: HList<a, HList<b, HList<c, HList<d, HNil>>>>): HList<d, HList<c, HList<b, HList<a, HNil>>>> | ||
public reverse<a, b, c, d, e>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HNil>>>>>): HList<e, HList<d, HList<c, HList<b, HList<a, HNil>>>>> | ||
public reverse<a, b, c, d, e, f>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HList<f, HNil>>>>>>): HList<f, HList<e, HList<d, HList<c, HList<b, HList<a, HNil>>>>>> | ||
public reverse<a, b, c, d, e, f, g>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HList<f, HList<g, HNil>>>>>>>): HList<g, HList<f, HList<e, HList<d, HList<c, HList<b, HList<a, HNil>>>>>>> | ||
public reverse<a, b, c, d, e, f, g, h>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HList<f, HList<g, HList<h, HNil>>>>>>>>): HList<h, HList<g, HList<f, HList<e, HList<d, HList<c, HList<b, HList<a, HNil>>>>>>>> | ||
public reverse<a, b, c, d, e, f, g, h, i>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HList<f, HList<g, HList<h, HList<i, HNil>>>>>>>>>): HList<i, HList<h, HList<g, HList<f, HList<e, HList<d, HList<c, HList<b, HList<a, HNil>>>>>>>>> | ||
public reverse(): HList<any, any> { | ||
return <this>this.array() | ||
.reduce<HNil | HList<a, any>>((l: HNil, e: a) => l.push(e), new HNil()); | ||
} | ||
public tuple<a>(this: HList<a, HNil>): [a] | ||
public tuple<a, b>(this: HList<a, HList<b, HNil>>): [a, b] | ||
public tuple<a, b, c>(this: HList<a, HList<b, HList<c, HNil>>>): [a, b, c] | ||
public tuple<a, b, c, d>(this: HList<a, HList<b, HList<c, HList<d, HNil>>>>): [a, b, c, d] | ||
public tuple<a, b, c, d, e>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HNil>>>>>): [a, b, c, d, e] | ||
public tuple<a, b, c, d, e, f>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HList<f, HNil>>>>>>): [a, b, c, d, e, f] | ||
public tuple<a, b, c, d, e, f, g>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HList<f, HList<g, HNil>>>>>>>): [a, b, c, d, e, f, g] | ||
public tuple<a, b, c, d, e, f, g, h>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HList<f, HList<g, HList<h, HNil>>>>>>>>): [a, b, c, d, e, f, g, h] | ||
public tuple<a, b, c, d, e, f, g, h, i>(this: HList<a, HList<b, HList<c, HList<d, HList<e, HList<f, HList<g, HList<h, HList<i, HNil>>>>>>>>>): [a, b, c, d, e, f, g, h, i] | ||
public tuple(): any[] { | ||
return this.array(); | ||
} | ||
public array(): never[] { | ||
return <never[]>concat([this.head()], this.tail().array()); | ||
} | ||
} |
@@ -5,6 +5,2 @@ import {List, Nil} from './list'; | ||
describe('List', () => { | ||
it('Nil', () => { | ||
const nil = new Nil(); | ||
}); | ||
it('List 1', () => { | ||
@@ -47,4 +43,34 @@ const list: List<number, Nil> = new Nil().push(0); | ||
it('compact', () => { | ||
{ | ||
const l: List<number, Nil> = new Nil().push(1).push(2).compact((n, m) => n - m); | ||
assert.deepStrictEqual(l.tuple(), [1]); | ||
} | ||
{ | ||
const l: List<number, List<number, Nil>> = new Nil().push(1).push(2).push(5).compact((n, m) => n - m); | ||
assert.deepStrictEqual(l.tuple(), [3, 1]); | ||
} | ||
}); | ||
it('reverse', () => { | ||
assert.deepStrictEqual(new Nil().push(0).push(1).push(2).reverse().array(), [0, 1, 2]); | ||
}); | ||
it('tuple', () => { | ||
{ | ||
const t: [number] = new Nil().push(1).tuple(); | ||
assert.deepStrictEqual(t, [1]); | ||
} | ||
{ | ||
const t: [number, number] = new Nil().push(2).push(1).tuple(); | ||
assert.deepStrictEqual(t, [1, 2]); | ||
} | ||
{ | ||
const t: [number, number, number] = new Nil().push(3).push(2).push(1).tuple(); | ||
assert.deepStrictEqual(t, [1, 2, 3]); | ||
} | ||
}); | ||
}); | ||
}); |
@@ -7,12 +7,19 @@ import {concat} from './concat'; | ||
private NIL: void; | ||
public push<a>(a: a): Cons<a, Nil> { | ||
constructor() { | ||
void this.NIL; | ||
} | ||
public push<a>(a: a): List<a, Nil> { | ||
return new Cons<a, Nil>(a, this); | ||
} | ||
public array(): never[] { | ||
return []; | ||
} | ||
} | ||
class Cons<a, c extends Nil | Cons<a, any>> { | ||
class Cons<a, c extends Nil | List<a, any>> { | ||
private CONS: a; | ||
constructor(private head_: a, private tail_: c) { | ||
void this.CONS; | ||
} | ||
public push(a: a): Cons<a, this> { | ||
public push(a: a): List<a, this> { | ||
return new Cons<a, this>(a, this); | ||
@@ -30,14 +37,30 @@ } | ||
} | ||
public modify(f: (a: a) => a): Cons<a, c> { | ||
public modify(f: (a: a) => a): List<a, c> { | ||
return (<any>this.tail().push)(f(this.head())); | ||
} | ||
public extend(f: (a: a) => a): Cons<a, this> { | ||
public extend(f: (a: a) => a): List<a, this> { | ||
return this.push(f(this.head())); | ||
} | ||
public compact<c extends Nil | List<a, any>>(this: List<a, List<a, c>>, f: (l: a, r: a) => a): List<a, c> { | ||
return this.tail().modify(r => f(this.head(), r)); | ||
} | ||
public reverse(): List<a, c> { | ||
return <this>this.array() | ||
.reduce<Nil | List<a, any>>((l: Nil, e: a) => l.push(e), new Nil()); | ||
} | ||
public tuple(this: List<a, Nil>): [a] | ||
public tuple(this: List<a, List<a, Nil>>): [a, a] | ||
public tuple(this: List<a, List<a, List<a, Nil>>>): [a, a, a] | ||
public tuple(this: List<a, List<a, List<a, List<a, Nil>>>>): [a, a, a, a] | ||
public tuple(this: List<a, List<a, List<a, List<a, List<a, Nil>>>>>): [a, a, a, a, a] | ||
public tuple(this: List<a, List<a, List<a, List<a, List<a, List<a, Nil>>>>>>): [a, a, a, a, a, a] | ||
public tuple(this: List<a, List<a, List<a, List<a, List<a, List<a, List<a, Nil>>>>>>>): [a, a, a, a, a, a, a] | ||
public tuple(this: List<a, List<a, List<a, List<a, List<a, List<a, List<a, List<a, Nil>>>>>>>>): [a, a, a, a, a, a, a, a] | ||
public tuple(this: List<a, List<a, List<a, List<a, List<a, List<a, List<a, List<a, List<a, Nil>>>>>>>>>): [a, a, a, a, a, a, a, a, a] | ||
public tuple(): a[] { | ||
return this.array(); | ||
} | ||
public array(): a[] { | ||
return concat( | ||
[this.head()], | ||
(<Cons<a, any>><any>this.tail()).array ? (<Cons<a, any>><any>this.tail()).array() : [] | ||
); | ||
return concat([this.head()], this.tail().array()); | ||
} | ||
} |
import {Functor} from './functor'; | ||
import {curry} from '../curry'; | ||
export abstract class Applicative<a> extends Functor<a> { | ||
public abstract fmap<b>(f: (a: a) => b): Applicative<b>; | ||
public abstract ap<b>(this: Applicative<(a: a) => b>, a: Applicative<a>): Applicative<b>; | ||
public abstract bind<b>(f: (a: a) => Applicative<b>): Applicative<b>; | ||
@@ -9,10 +11,9 @@ } | ||
export declare function pure<a>(a: a): Applicative<a>; | ||
export function ap<_, b>(ff: Applicative<() => b>): () => Applicative<b>; | ||
export function ap<a, b>(ff: Applicative<(a: a) => b>, fa: Applicative<a>): Applicative<b>; | ||
export function ap<a, b>(ff: Applicative<(a: a) => b>): (fa: Applicative<a>) => Applicative<b>; | ||
export function ap<a, b>(ff: Applicative<(a: a) => b>, fa?: Applicative<a>): Applicative<b> | ((fa: Applicative<a>) => Applicative<b>) { | ||
return fa | ||
? ff.bind(f => fa.fmap(a => f(a))) | ||
: (fa: Applicative<a>) => ff.bind(f => fa.fmap(a => f(a))); | ||
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>; | ||
export function ap<a, b>(af: Applicative<(a: a) => b>, aa?: Applicative<a>): Applicative<b> | ((fa: 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))); | ||
} | ||
} |
@@ -11,2 +11,12 @@ import {Monad} from './monad'; | ||
} | ||
public ap<b, z>(this: Either<a, (b: b) => z>, b: Either<a, b>): Either<a, z> | ||
public ap<b, c, z>(this: Either<a, (b: b, c: c) => z>, b: Either<a, b>): Either<a, (c: c) => z> | ||
public ap<b, c, d, z>(this: Either<a, (b: b, c: c, d: d) => z>, b: Either<a, b>): Either<a, (c: c, d: d) => z> | ||
public ap<b, c, d, e, z>(this: Either<a, (b: b, c: c, d: d, e: e) => z>, b: Either<a, b>): Either<a, (c: c, d: d, e: e) => z> | ||
public ap<b, c, d, e, f, z>(this: Either<a, (b: b, c: c, d: d, e: e, f: f) => z>, b: Either<a, b>): Either<a, (c: c, d: d, e: e, f: f) => z> | ||
public ap<b, z>(this: Either<a, (b: b) => z>, b: Either<a, b>): Either<a, z> { | ||
return Either.ap(this, b); | ||
} | ||
public bind(f: (b: b) => Left<a>): Either<a, b> | ||
public bind<c>(f: (b: b) => Either<a, c>): Either<a, c> | ||
public bind<c>(f: (b: b) => Either<a, c>): Either<a, c> { | ||
@@ -32,4 +42,4 @@ return new Either<a, c>(() => { | ||
return !right | ||
? this.evaluate().extract(left) | ||
: this.fmap(right).extract(left); | ||
? this.evaluate().extract(left!) | ||
: this.fmap(right).extract(left!); | ||
} | ||
@@ -43,5 +53,4 @@ } | ||
} | ||
export declare function ap<e, _, b>(ff: Either<e, () => b>): () => Either<e, b> | ||
export declare function ap<e, a, b>(ff: Either<e, (a: a) => b>, fa: Either<e, a>): Either<e, b> | ||
export declare function ap<e, a, b>(ff: Either<e, (a: a) => b>): (fa: Either<e, a>) => Either<e, b> | ||
export declare function ap<e, a, b>(mf: Either<e, (a: a) => b>, ma: Either<e, a>): Either<e, b> | ||
export declare function ap<e, a, b>(mf: Either<e, (a: a) => b>): (ma: Either<e, a>) => Either<e, b> | ||
export const Return = pure; | ||
@@ -58,6 +67,6 @@ export declare function bind<e, a, b>(m: Either<e, a>, f: (a: a) => Either<e, b>): Either<e, b> | ||
} | ||
public bind<_ extends a>(f: (b: any) => Either<a, any>): Either<a, any> | ||
public bind<_ extends a, b>(f: (b: b) => Either<a, b>): Either<a, b> | ||
public bind<_ extends a, b>(f: (b: b) => Either<a, b>): Either<a, b> { | ||
return this; | ||
public bind(_: (b: any) => Left<a>): Left<a> | ||
public bind<c>(_: (b: any) => Either<a, c>): Either<a, c> | ||
public bind<c>(_: (b: any) => Either<a, c>): Either<a, c> { | ||
return <Either<a, c>>this; | ||
} | ||
@@ -79,3 +88,3 @@ public extract(): any | ||
} | ||
public bind<a>(f: (b: b) => Either<a, b>): Either<a, b> | ||
public bind<c>(f: (b: b) => Right<c>): Right<c> | ||
public bind<a, c>(f: (b: b) => Either<a, c>): Either<a, c> | ||
@@ -88,3 +97,3 @@ public bind<a, c>(f: (b: b) => Either<a, c>): Either<a, c> { | ||
public extract<c>(left: (a: void) => c, right: (b: b) => c): c | ||
public extract<c>(left?: (a: void) => c, right?: (b: b) => c): b | c { | ||
public extract<c>(_?: (a: void) => c, right?: (b: b) => c): b | c { | ||
return !right | ||
@@ -96,4 +105,4 @@ ? this.b | ||
function throwCallError<T>(): T { | ||
function throwCallError(): never { | ||
throw new Error(`Spica: Either: Invalid thunk call.`); | ||
} |
import {Either, Left, Right} from './either'; | ||
import {curry} from '../curry'; | ||
@@ -7,3 +6,3 @@ describe('Unit: lib/either', () => { | ||
function throwError(msg: string): any { | ||
function throwError(msg: string): never { | ||
throw new Error(msg); | ||
@@ -13,12 +12,2 @@ } | ||
describe('Either', () => { | ||
it('Either type', () => { | ||
const left: Either<Error, number> = Left<Error>(new Error()); | ||
const right: Either<Error, number> = Right<number>(0); | ||
const either: Either<Error, number> = Right(0).bind<Error>(n => Right(n) || Left(new Error())); | ||
}); | ||
it('Left type', () => { | ||
const left: Left<Error> = Left<Error>(new Error()); | ||
}); | ||
it('Left', () => { | ||
@@ -35,3 +24,3 @@ const result = Return(0) | ||
const result = Return(Return(0)) | ||
.bind(m => m.bind(n => Left(NaN)).bind(throwError)) | ||
.bind(m => m.bind(_ => Left(NaN)).bind(throwError)) | ||
.bind(throwError) | ||
@@ -42,6 +31,2 @@ .extract(_ => 'Nothing'); | ||
it('Right type', () => { | ||
const right: Right<number> = Right(0); | ||
}); | ||
it('Right', () => { | ||
@@ -65,5 +50,5 @@ const result = Return(0) | ||
const result = Return(0) | ||
.bind<number>(n => Right(n) || Left(0) || Right(n).bind(n => Right(n) || Left(0))) | ||
.bind<number>(n => Right(n) || Left(0) || Right(n).bind(n => Right(n) || Left(0))) | ||
.extract((n) => n + ''); | ||
.bind<number, number>(n => <Right<number> | Left<number> | Either<number, number>>Right(n).bind(n => <Right<number> | Left<number>>Right(n) || Left(0))) | ||
.bind(n => <Right<number> | Left<number> | Either<number, number>>Right(n).bind(n => <Right<number> | Left<number>>Right(n) || Left(0))) | ||
.extract(n => n + ''); | ||
assert(result === 0); | ||
@@ -122,11 +107,9 @@ }); | ||
assert.strictEqual( | ||
Either.ap( | ||
Either.pure(curry((a: number) => a))) | ||
(Either.pure(1)) | ||
Either.pure((a: number) => a) | ||
.ap(Either.pure(1)) | ||
.extract(), | ||
1); | ||
assert.strictEqual( | ||
Either.ap( | ||
Either.pure(curry(throwError))) | ||
(Left(0)) | ||
Either.pure(throwError) | ||
.ap(Left(0)) | ||
.extract(n => n + 1), | ||
@@ -138,6 +121,5 @@ 1); | ||
assert.strictEqual( | ||
Either.ap(Either.ap( | ||
Either.pure(curry((a: number, b: number) => a + b))) | ||
(Either.pure(1))) | ||
(Either.pure(2)) | ||
Either.pure((a: number, b: number) => a + b) | ||
.ap(Either.pure(1)) | ||
.ap(Either.pure(2)) | ||
.extract(), | ||
@@ -149,7 +131,6 @@ 3); | ||
assert.strictEqual( | ||
Either.ap(Either.ap(Either.ap( | ||
Either.pure(curry((a: number, b: number, c: number) => a + b + c))) | ||
(Either.pure(1))) | ||
(Either.pure(2))) | ||
(Either.pure(3)) | ||
Either.pure((a: number, b: number, c: number) => a + b + c) | ||
.ap(Either.pure(1)) | ||
.ap(Either.pure(2)) | ||
.ap(Either.pure(3)) | ||
.extract(), | ||
@@ -176,3 +157,2 @@ 6); | ||
it('Monad law 2', () => { | ||
const f = (n: number) => Return(n + 1); | ||
const x = 0; | ||
@@ -192,3 +172,3 @@ const ma = Return(x); | ||
const mb = Return(x) | ||
.bind(n => | ||
.bind(x => | ||
f(x) | ||
@@ -195,0 +175,0 @@ .bind(g)); |
@@ -13,2 +13,4 @@ import * as Monad from './either.impl'; | ||
export type Left<a> = Monad.Left<a>; | ||
export function Left<a>(a: a): Left<a> | ||
export function Left<a, b>(a: a): Either<a, b> | ||
export function Left<a>(a: a): Left<a> { | ||
@@ -18,4 +20,6 @@ return new Monad.Left<a>(a); | ||
export type Right<b> = Monad.Right<b>; | ||
export function Right<b>(b: b): Right<b> | ||
export function Right<a, b>(b: b): Either<a, b> | ||
export function Right<b>(b: b): Right<b> { | ||
return new Monad.Right<b>(b); | ||
} |
export abstract class Lazy<a> { | ||
constructor(protected thunk?: () => Lazy<a>) { | ||
constructor(protected thunk: () => Lazy<a>) { | ||
} | ||
private memory_: this; | ||
protected evaluate(): this { | ||
return this.memory_ = this.memory_ || <this>this.thunk(); | ||
return this.memory_ = this.memory_ || <this>this.thunk!(); | ||
} | ||
} |
import {MonadPlus} from './monadplus'; | ||
import {curry} from '../curry'; | ||
@@ -12,3 +11,11 @@ export class Maybe<a> extends MonadPlus<a> { | ||
} | ||
public bind<b>(f: (a: a) => Nothing): Maybe<a> | ||
public ap<a, z>(this: Maybe<(a: a) => z>, a: Maybe<a>): Maybe<z> | ||
public ap<a, b, z>(this: Maybe<(a: a, b: b) => z>, a: Maybe<a>): Maybe<(b: b) => z> | ||
public ap<a, b, c, z>(this: Maybe<(a: a, b: b, c: c) => z>, a: Maybe<a>): Maybe<(b: b, c: c) => z> | ||
public ap<a, b, c, d, z>(this: Maybe<(a: a, b: b, c: c, d: d) => z>, a: Maybe<a>): Maybe<(b: b, c: c, d: d) => z> | ||
public ap<a, b, c, d, e, z>(this: Maybe<(a: a, b: b, c: c, d: d, e: e) => z>, a: Maybe<a>): Maybe<(b: b, c: c, d: d, e: e) => z> | ||
public ap<a, z>(this: Maybe<(...as: any[]) => z>, a: Maybe<a>): Maybe<z> { | ||
return Maybe.ap(this, a); | ||
} | ||
public bind(f: (a: a) => Nothing): Maybe<a> | ||
public bind<b>(f: (a: a) => Maybe<b> | Nothing): Maybe<b> | ||
@@ -35,4 +42,4 @@ public bind<b>(f: (a: a) => Maybe<b> | Nothing): Maybe<b> { | ||
return !just | ||
? this.evaluate().extract(nothing) | ||
: this.fmap(just).extract(nothing); | ||
? this.evaluate().extract(nothing!) | ||
: this.fmap(just).extract(nothing!); | ||
} | ||
@@ -46,11 +53,9 @@ } | ||
} | ||
export declare function ap<_, b>(ff: Maybe<() => b>): () => Maybe<b> | ||
export declare function ap<a, b>(ff: Maybe<(a: a) => b>, fa: Maybe<a>): Maybe<b> | ||
export declare function ap<a, b>(ff: Maybe<(a: a) => b>): (fa: Maybe<a>) => Maybe<b> | ||
export declare function ap<a, b>(mf: Maybe<(a: a) => b>, ma: Maybe<a>): Maybe<b> | ||
export declare function ap<a, b>(mf: Maybe<(a: a) => b>): (ma: Maybe<a>) => Maybe<b> | ||
export const Return = pure; | ||
export declare function bind<a, b>(m: Maybe<a>, f: (a: a) => Nothing): Maybe<a> | ||
export declare function bind<a>(m: Maybe<a>, f: (a: a) => Nothing): Maybe<a> | ||
export declare function bind<a, b>(m: Maybe<a>, f: (a: a) => Maybe<b> | Nothing): Maybe<b> | ||
export declare function bind<a>(m: Maybe<a>): PartialBind<a> | ||
interface PartialBind<a> { | ||
<b>(f: (a: a) => Nothing): Maybe<a>; | ||
export declare function bind<a>(m: Maybe<a>): { | ||
(f: (a: a) => Nothing): Maybe<a>; | ||
<b>(f: (a: a) => Maybe<b> | Nothing): Maybe<b>; | ||
@@ -66,3 +71,3 @@ } | ||
} | ||
public bind<b>(f: (a: a) => Nothing): Maybe<a> | ||
public bind(f: (a: a) => Nothing): Maybe<a> | ||
public bind<b>(f: (a: a) => Maybe<b> | Nothing): Maybe<b> | ||
@@ -75,3 +80,3 @@ public bind<b>(f: (a: a) => Maybe<b> | Nothing): Maybe<b> { | ||
public extract<b>(nothing: () => b, just: (a: a) => b): b | ||
public extract<b>(nothing?: () => b, just?: (a: a) => b): a | b { | ||
public extract<b>(_?: () => b, just?: (a: a) => b): a | b { | ||
return !just | ||
@@ -89,5 +94,5 @@ ? this.a | ||
} | ||
public bind<b>(f: (a: any) => Nothing): Maybe<any> | ||
public bind(f: (a: any) => Nothing): Nothing | ||
public bind<b>(f: (a: any) => Maybe<b> | Nothing): Maybe<b> | ||
public bind<b>(f: (a: any) => Maybe<b> | Nothing): Maybe<b> { | ||
public bind<b>(_: (a: any) => Maybe<b> | Nothing): Maybe<b> { | ||
return this; | ||
@@ -105,3 +110,6 @@ } | ||
export namespace Maybe { | ||
export const mzero: Maybe<any> = new Nothing(); | ||
export const mzero: Nothing = new Nothing(); | ||
export function mplus<a>(ml: Maybe<a>, mr: Nothing): Maybe<a> | ||
export function mplus<a>(ml: Nothing, mr: Maybe<a>): Maybe<a> | ||
export function mplus<a>(ml: Maybe<a>, mr: Maybe<a>): Maybe<a> | ||
export function mplus<a>(ml: Maybe<a>, mr: Maybe<a>): Maybe<a> { | ||
@@ -115,4 +123,4 @@ return new Maybe<a>(() => | ||
function throwCallError<T>(): T { | ||
function throwCallError(): never { | ||
throw new Error(`Spica: Maybe: Invalid thunk call.`); | ||
} |
import {Maybe, Just, Nothing} from './maybe'; | ||
import {curry} from '../curry'; | ||
import {Sequence} from './sequence'; | ||
@@ -8,3 +7,3 @@ | ||
function throwError(msg: string): any { | ||
function throwError(msg: string): never { | ||
throw new Error(msg); | ||
@@ -14,12 +13,2 @@ } | ||
describe('Maybe', () => { | ||
it('Maybe type', () => { | ||
const just: Maybe<number> = Just(0); | ||
const nothing: Maybe<number> = Nothing; | ||
const maybe: Maybe<number> = Just(0).bind<number>(n => Just(n) || Nothing); | ||
}); | ||
it('Just type', () => { | ||
const just: Just<number> = Just(0); | ||
}); | ||
it('Just', () => { | ||
@@ -41,6 +30,2 @@ const result = Return(0) | ||
it('Nothing type', () => { | ||
const nothing: Nothing = Nothing; | ||
}); | ||
it('Nothing', () => { | ||
@@ -57,3 +42,3 @@ const result = Return(0) | ||
const result = Return(Return('')) | ||
.bind(m => m.bind(n => Nothing).bind(throwError)) | ||
.bind(m => m.bind(_ => Nothing).bind(throwError)) | ||
.bind(throwError) | ||
@@ -66,4 +51,4 @@ .extract(() => 'Nothing'); | ||
const result = Return(0) | ||
.bind(n => Just(n) || Nothing || Just(n).bind<number>(n => Just(n) || Nothing)) | ||
.bind(n => Just(n) || Nothing || Just(n).bind<number>(n => Just(n) || Nothing)) | ||
.bind(n => <Just<number> | Nothing | Maybe<number>>Just(n).bind(n => <Just<number> | Nothing>Just(n) || Nothing)) | ||
.bind(n => <Just<number> | Nothing | Maybe<number>>Just(n).bind(n => <Just<number> | Nothing>Just(n) || Nothing)) | ||
.extract(() => 'Nothing'); | ||
@@ -123,11 +108,9 @@ assert(result === 0); | ||
assert.strictEqual( | ||
Maybe.ap( | ||
Maybe.pure(curry((a: number) => a))) | ||
(Maybe.pure(1)) | ||
Maybe.pure((a: number) => a) | ||
.ap(Maybe.pure(1)) | ||
.extract(), | ||
1); | ||
assert.strictEqual( | ||
Maybe.ap( | ||
Maybe.pure(curry(throwError))) | ||
(Nothing) | ||
Maybe.pure(throwError) | ||
.ap(Nothing) | ||
.extract(() => 0), | ||
@@ -139,6 +122,5 @@ 0); | ||
assert.strictEqual( | ||
Maybe.ap(Maybe.ap( | ||
Maybe.pure(curry((a: number, b: number) => a + b))) | ||
(Maybe.pure(1))) | ||
(Maybe.pure(2)) | ||
Maybe.pure((a: number, b: number) => a + b) | ||
.ap(Maybe.pure(1)) | ||
.ap(Maybe.pure(2)) | ||
.extract(), | ||
@@ -150,7 +132,6 @@ 3); | ||
assert.strictEqual( | ||
Maybe.ap(Maybe.ap(Maybe.ap( | ||
Maybe.pure(curry((a: number, b: number, c: number) => a + b + c))) | ||
(Maybe.pure(1))) | ||
(Maybe.pure(2))) | ||
(Maybe.pure(3)) | ||
Maybe.pure((a: number, b: number, c: number) => a + b + c) | ||
.ap(Maybe.pure(1)) | ||
.ap(Maybe.pure(2)) | ||
.ap(Maybe.pure(3)) | ||
.extract(), | ||
@@ -177,3 +158,2 @@ 6); | ||
it('Monad law 2', () => { | ||
const f = (n: number) => Return(n + 1); | ||
const x = 0; | ||
@@ -193,3 +173,3 @@ const ma = Return(x); | ||
const mb = Return(x) | ||
.bind(n => | ||
.bind(x => | ||
f(x) | ||
@@ -196,0 +176,0 @@ .bind(g)); |
import {Sequence} from './sequence'; | ||
import {curry} from '../curry'; | ||
@@ -57,11 +56,9 @@ describe('Unit: lib/monad/sequence', () => { | ||
assert.deepStrictEqual( | ||
Sequence.ap( | ||
Sequence.pure(curry((a: number) => a))) | ||
(Sequence.pure(1)) | ||
Sequence.pure((a: number) => a) | ||
.ap(Sequence.pure(1)) | ||
.extract(), | ||
[1]); | ||
assert.deepStrictEqual( | ||
Sequence.ap( | ||
Sequence.pure(curry((a: number) => a)), | ||
(Sequence.pure(1))) | ||
Sequence.pure((a: number) => a) | ||
.ap(Sequence.pure(1)) | ||
.extract(), | ||
@@ -73,6 +70,5 @@ [1]); | ||
assert.deepStrictEqual( | ||
Sequence.ap(Sequence.ap( | ||
Sequence.pure(curry((a: number, b: number) => a + b))) | ||
(Sequence.pure(1))) | ||
(Sequence.pure(2)) | ||
Sequence.pure((a: number, b: number) => a + b) | ||
.ap(Sequence.pure(1)) | ||
.ap(Sequence.pure(2)) | ||
.extract(), | ||
@@ -84,7 +80,6 @@ [3]); | ||
assert.deepStrictEqual( | ||
Sequence.ap(Sequence.ap(Sequence.ap( | ||
Sequence.pure(curry((a: number, b: number, c: number) => a + b + c))) | ||
(Sequence.pure(1))) | ||
(Sequence.pure(2))) | ||
(Sequence.pure(3)) | ||
Sequence.pure((a: number, b: number, c: number) => a + b + c) | ||
.ap(Sequence.pure(1)) | ||
.ap(Sequence.pure(2)) | ||
.ap(Sequence.pure(3)) | ||
.extract(), | ||
@@ -94,2 +89,19 @@ [6]); | ||
it('combination 1', () => { | ||
assert.deepStrictEqual( | ||
Sequence.from([(n: number) => n, (n: number) => -n]) | ||
.ap(Sequence.from([1, 2])) | ||
.extract(), | ||
[1, 2, -1, -2]); | ||
}); | ||
it('combination 2', () => { | ||
assert.deepStrictEqual( | ||
Sequence.from([(n: number, m: number) => n + m, (n: number, m: number) => n * m]) | ||
.ap(Sequence.from([1, 2])) | ||
.ap(Sequence.from([3, 4])) | ||
.extract(), | ||
[4, 5, 5, 6, 3, 4, 6, 8]); | ||
}); | ||
}); | ||
@@ -112,3 +124,2 @@ | ||
it('Monad law 2', () => { | ||
const f = (n: number) => Sequence.Return(n + 1); | ||
const x = 0; | ||
@@ -128,3 +139,3 @@ const ma = Sequence.Return(x); | ||
const mb = Sequence.Return(x) | ||
.bind(n => | ||
.bind(x => | ||
f(x) | ||
@@ -131,0 +142,0 @@ .bind(g)); |
@@ -29,2 +29,3 @@ import {Sequence} from './sequence/core'; | ||
import fmap from './sequence/member/instance/fmap'; | ||
import ap from './sequence/member/instance/ap'; | ||
import bind from './sequence/member/instance/bind'; | ||
@@ -71,2 +72,3 @@ import mapM from './sequence/member/instance/mapM'; | ||
fmap, | ||
ap, | ||
bind, | ||
@@ -73,0 +75,0 @@ mapM, |
@@ -8,3 +8,3 @@ import {MonadPlus} from '../monadplus'; | ||
) { | ||
super(); | ||
super(throwCallError); | ||
} | ||
@@ -28,5 +28,4 @@ } | ||
export declare function pure<a>(a: a): Sequence<a, number>; | ||
export declare function ap<a, b>(ff: Sequence<() => b, any>): () => Sequence<() => b, [Sequence.Iterator<Sequence<b, any>>, Sequence.Iterator<b>]> | ||
export declare function ap<a, b>(ff: Sequence<(a: a) => b, any>, fa: Sequence<a, any>): Sequence<b, [Sequence.Iterator<Sequence<b, any>>, Sequence.Iterator<b>]> | ||
export declare function ap<a, b>(ff: Sequence<(a: a) => b, any>): (fa: Sequence<a, any>) => Sequence<b, [Sequence.Iterator<Sequence<b, any>>, Sequence.Iterator<b>]> | ||
export declare function ap<a, b>(mf: Sequence<(a: a) => b, any>, ma: Sequence<a, any>): Sequence<b, [Sequence.Iterator<Sequence<b, any>>, Sequence.Iterator<b>]>; | ||
export declare function ap<a, b>(mf: Sequence<(a: a) => b, any>): (ma: Sequence<a, any>) => Sequence<b, [Sequence.Iterator<Sequence<b, any>>, Sequence.Iterator<b>]>; | ||
export declare const Return: typeof pure; | ||
@@ -45,2 +44,7 @@ export declare function bind<a, b>(m: Sequence<a, any>, f: (a: a) => Sequence<b, any>): Sequence<b, Sequence.Iterator<a>>; | ||
fmap<b>(f: (a: a) => b): Sequence<b, Sequence.Iterator<a>>; | ||
ap<a, z>(this: Sequence<(a: a) => z, any>, a: Sequence<a, any>): Sequence<z, [Sequence.Iterator<Sequence<z, any>>, Sequence.Iterator<z>]>; | ||
ap<a, b, z>(this: Sequence<(a: a, b: b) => z, any>, a: Sequence<a, any>): Sequence<(b: b) => z, [Sequence.Iterator<Sequence<z, any>>, Sequence.Iterator<z>]>; | ||
ap<a, b, c, z>(this: Sequence<(a: a, b: b, c: c) => z, any>, a: Sequence<a, any>): Sequence<(b: b, c: c) => z, [Sequence.Iterator<Sequence<z, any>>, Sequence.Iterator<z>]>; | ||
ap<a, b, c, d, z>(this: Sequence<(a: a, b: b, c: c, d: d) => z, any>, a: Sequence<a, any>): Sequence<(b: b, c: c, d: d) => z, [Sequence.Iterator<Sequence<z, any>>, Sequence.Iterator<z>]>; | ||
ap<a, b, c, d, e, z>(this: Sequence<(a: a, b: b, c: c, d: d, e: e) => z, any>, a: Sequence<a, any>): Sequence<(b: b, c: c, d: d, e: e) => z, [Sequence.Iterator<Sequence<z, any>>, Sequence.Iterator<z>]>; | ||
bind<b>(f: (a: a) => Sequence<b, any>): Sequence<b, [Sequence.Iterator<Sequence<b, any>>, Sequence.Iterator<b>]>; | ||
@@ -71,3 +75,3 @@ mapM<b>(f: (a: a) => Sequence<b, any>): Sequence<b[], [Sequence.Iterator<Sequence<b[], any>>, Sequence.Iterator<b[]>]>; | ||
case 0: | ||
return <Sequence.Data<a, z>>[]; | ||
return <Sequence.Data<a, z>><any[]>[]; | ||
case 1: | ||
@@ -96,3 +100,3 @@ return <Sequence.Data<a, z>><any[]>[a]; | ||
export namespace Iterator { | ||
export const done: Sequence.Iterator<any> = () => <Sequence.Thunk<any>>[void 0, done, -1]; | ||
export let /* const */ done: Sequence.Iterator<any> = () => <Sequence.Thunk<any>>[void 0, done, -1]; | ||
export function when<a, b>( | ||
@@ -126,1 +130,5 @@ thunk: Thunk<a>, | ||
} | ||
function throwCallError(): never { | ||
throw new Error(`Spica: Sequence: Invalid thunk call.`); | ||
} |
@@ -56,3 +56,3 @@ import {Sequence} from '../../../sequence'; | ||
.take(3) | ||
.bind(n => Sequence.from([])) | ||
.bind(_ => Sequence.from([])) | ||
.take(Infinity) | ||
@@ -59,0 +59,0 @@ .extract(), |
@@ -9,3 +9,3 @@ import {Sequence} from '../../../sequence'; | ||
assert.deepStrictEqual( | ||
new Sequence<number, number>((n = 0, cons) => cons()) | ||
new Sequence<number, number>((_ = 0, cons) => cons()) | ||
.dropUntil(() => true) | ||
@@ -18,3 +18,3 @@ .extract(), | ||
assert.deepStrictEqual( | ||
new Sequence<number, number>((n = 0, cons) => cons()) | ||
new Sequence<number, number>((_ = 0, cons) => cons()) | ||
.dropUntil(() => false) | ||
@@ -21,0 +21,0 @@ .extract(), |
@@ -9,3 +9,3 @@ import {Sequence} from '../../../sequence'; | ||
assert.deepStrictEqual( | ||
new Sequence<number, number>((n = 0, cons) => cons()) | ||
new Sequence<number, number>((_ = 0, cons) => cons()) | ||
.dropWhile(() => false) | ||
@@ -18,3 +18,3 @@ .extract(), | ||
assert.deepStrictEqual( | ||
new Sequence<number, number>((n = 0, cons) => cons()) | ||
new Sequence<number, number>((_ = 0, cons) => cons()) | ||
.dropWhile(() => true) | ||
@@ -21,0 +21,0 @@ .extract(), |
@@ -13,3 +13,3 @@ import {Sequence} from '../../core'; | ||
default: { | ||
const x = xs.shift(); | ||
const x = xs.shift()!; | ||
return f(x) | ||
@@ -16,0 +16,0 @@ .bind<a[]>(b => |
@@ -5,9 +5,9 @@ import {Sequence} from '../../core'; | ||
public fold<b>(f: (a: a, b: Sequence<b, any>) => Sequence<b, any>, z: Sequence<b, any>): Sequence<b, [Sequence.Iterator<Sequence<b, any>>, Sequence.Iterator<b>]> { | ||
return new Sequence<Sequence<b, any>, [Sequence.Iterator<a>, number]>(([iter, i] =[() => this.iterate(), 0]) => | ||
return new Sequence<Sequence<b, any>, Sequence.Iterator<a>>((iter = () => this.iterate()) => | ||
Sequence.Iterator.when( | ||
iter(), | ||
() => | ||
Sequence.Data.cons<Sequence<b, any>, Sequence.Iterator<a>>(z), | ||
thunk => | ||
Sequence.Data.cons<Sequence<b, any>, [Sequence.Iterator<a>, number]>(z), | ||
thunk => | ||
Sequence.Data.cons<Sequence<b, any>, [Sequence.Iterator<a>, number]>( | ||
Sequence.Data.cons<Sequence<b, any>, Sequence.Iterator<a>>( | ||
f( | ||
@@ -14,0 +14,0 @@ Sequence.Thunk.value(thunk), |
@@ -6,3 +6,3 @@ import {Sequence} from '../../../sequence'; | ||
it('', () => { | ||
let thunk = new Sequence<number, number>((n = 0, cons) => cons()).iterate(); | ||
let thunk = new Sequence<number, number>((_ = 0, cons) => cons()).iterate(); | ||
assert.deepStrictEqual(thunk, [void 0, Sequence.Iterator.done, -1]); | ||
@@ -9,0 +9,0 @@ |
@@ -10,9 +10,9 @@ import {Sequence} from '../../core'; | ||
? this.memory.has(i) | ||
? this.memory.get(i) | ||
: this.memory.set(i, this.cons(z, Sequence.Data.cons)).get(i) | ||
: this.cons(z, Sequence.Data.cons); | ||
? this.memory.get(i)! | ||
: this.memory.set(i, this.cons(z!, Sequence.Data.cons)).get(i)! | ||
: this.cons(z!, Sequence.Data.cons); | ||
switch (data.length) { | ||
case 0: | ||
return <Sequence.Thunk<a>>[ | ||
void 0, | ||
<a><any>void 0, | ||
Sequence.Iterator.done, | ||
@@ -19,0 +19,0 @@ -1 |
@@ -12,3 +12,3 @@ import {Sequence} from '../../../sequence'; | ||
.take(0) | ||
.mapM(n => Sequence.from([])) | ||
.mapM(_ => Sequence.from([])) | ||
.extract(), | ||
@@ -43,3 +43,3 @@ []); | ||
.take(1) | ||
.mapM(n => Sequence.from([])) | ||
.mapM(_ => Sequence.from([])) | ||
.extract(), | ||
@@ -46,0 +46,0 @@ []); |
@@ -13,3 +13,3 @@ import {Sequence} from '../../core'; | ||
default: { | ||
const x = xs.shift(); | ||
const x = xs.shift()!; | ||
return f(x) | ||
@@ -16,0 +16,0 @@ .bind<b[]>(y => |
import {Sequence} from '../../core'; | ||
import {concat} from '../../../../concat'; | ||
@@ -56,3 +55,2 @@ export default class <a, z> extends Sequence<a, z> { | ||
const y = Sequence.Thunk.value(yt); | ||
const ys = Sequence.resume(Sequence.Thunk.iterator(yt)); | ||
const [us, zs] = interleave_( | ||
@@ -59,0 +57,0 @@ as => f(Sequence.mappend(Sequence.from([y]), as)), |
@@ -9,3 +9,3 @@ import {Sequence} from '../../../sequence'; | ||
assert.deepStrictEqual( | ||
new Sequence<number, number>((n = 0, cons) => cons()) | ||
new Sequence<number, number>((_ = 0, cons) => cons()) | ||
.takeUntil(() => true) | ||
@@ -18,3 +18,3 @@ .extract(), | ||
assert.deepStrictEqual( | ||
new Sequence<number, number>((n = 0, cons) => cons()) | ||
new Sequence<number, number>((_ = 0, cons) => cons()) | ||
.takeUntil(() => false) | ||
@@ -21,0 +21,0 @@ .extract(), |
@@ -9,3 +9,3 @@ import {Sequence} from '../../../sequence'; | ||
assert.deepStrictEqual( | ||
new Sequence<number, number>((n = 0, cons) => cons()) | ||
new Sequence<number, number>((_ = 0, cons) => cons()) | ||
.takeWhile(() => true) | ||
@@ -18,3 +18,3 @@ .extract(), | ||
assert.deepStrictEqual( | ||
new Sequence<number, number>((n = 0, cons) => cons()) | ||
new Sequence<number, number>((_ = 0, cons) => cons()) | ||
.takeWhile(() => false) | ||
@@ -21,0 +21,0 @@ .extract(), |
@@ -44,3 +44,3 @@ import {Sequence} from '../../../sequence'; | ||
assert.deepStrictEqual( | ||
Sequence.difference(Sequence.from([]), Sequence.from([]), (a, b) => a - b).take(3).extract(), | ||
Sequence.difference(Sequence.from([]), Sequence.from([]), () => 0).take(3).extract(), | ||
[]); | ||
@@ -47,0 +47,0 @@ }); |
@@ -44,3 +44,3 @@ import {Sequence} from '../../../sequence'; | ||
assert.deepStrictEqual( | ||
Sequence.intersect(Sequence.from([]), Sequence.from([]), (a, b) => a - b).take(3).extract(), | ||
Sequence.intersect(Sequence.from([]), Sequence.from([]), () => 0).take(3).extract(), | ||
[]); | ||
@@ -47,0 +47,0 @@ }); |
@@ -44,3 +44,3 @@ import {Sequence} from '../../../sequence'; | ||
assert.deepStrictEqual( | ||
Sequence.union(Sequence.from([]), Sequence.from([]), (a, b) => a - b).take(3).extract(), | ||
Sequence.union(Sequence.from([]), Sequence.from([]), () => 0).take(3).extract(), | ||
[]); | ||
@@ -47,0 +47,0 @@ }); |
@@ -122,3 +122,3 @@ import {Observable} from './observable'; | ||
const ob = new Observable<string[], TestEvent, void>(); | ||
ob.on(['test'], data => ++cnt === 1 && done()); | ||
ob.on(['test'], () => assert(++cnt === 1) || done()); | ||
ob.emit(['test'], new TestEvent('TEST')); | ||
@@ -130,5 +130,4 @@ }); | ||
const ob = new Observable<string[], TestEvent, void>(); | ||
ob.on(['test', '0'], data => ++cnt === 2 && done()); | ||
ob.on(['test', '0'], () => assert(++cnt === 1) || done()); | ||
ob.emit(['test', '0'], new TestEvent('TEST')); | ||
ob.emit(['test', '0'], new TestEvent('TEST')); | ||
}); | ||
@@ -139,3 +138,3 @@ | ||
const ob = new Observable<string[], number, void>(); | ||
ob.once(['test'], data => ob.emit(['test'], 1, data => assert(++cnt === 1 && data === 1))); | ||
ob.once(['test'], () => ob.emit(['test'], 1, data => assert(++cnt === 1 && data === 1))); | ||
ob.emit(['test'], 0, data => assert(++cnt === 2 && data === 0) || done()); | ||
@@ -142,0 +141,0 @@ }); |
@@ -5,3 +5,3 @@ import {Observer, Publisher} from 'spica'; | ||
interface SubscriberMapNode<T, D, R> { | ||
parent: SubscriberMapNode<T, D, R>; | ||
parent: SubscriberMapNode<T, D, R> | undefined; | ||
childrenMap: SubscriberMap<T, D, R>; | ||
@@ -74,3 +74,3 @@ childrenList: string[]; | ||
public reflect(namespace: T, data: D): R[] { | ||
let results: R[]; | ||
let results: R[] = []; | ||
void this.emit(namespace, <D>data, (_, r) => results = r); | ||
@@ -83,3 +83,3 @@ assert(Array.isArray(results)); | ||
void this.refsBelow_(this.seekNode_(types)) | ||
.reduce((_, sub) => { | ||
.reduce<void>((_, sub) => { | ||
const [, , monitor, subscriber] = sub; | ||
@@ -101,3 +101,3 @@ if (monitor) return; | ||
void this.refsAbove_(this.seekNode_(types)) | ||
.reduce((_, sub) => { | ||
.reduce<void>((_, sub) => { | ||
const [, , monitor, subscriber] = sub; | ||
@@ -175,3 +175,3 @@ if (!monitor) return; | ||
} | ||
private throwTypeErrorIfInvalidSubscriber_(subscriber: Subscriber<D, R>, types: T): void { | ||
private throwTypeErrorIfInvalidSubscriber_(subscriber: Subscriber<D, R> | undefined, types: T): void { | ||
switch (typeof subscriber) { | ||
@@ -178,0 +178,0 @@ case 'function': |
@@ -125,3 +125,3 @@ import {Supervisor} from './supervisor'; | ||
case 3: { | ||
assert(++cnt === 7); | ||
assert(++cnt === 6); | ||
assert(data === 3); | ||
@@ -131,3 +131,3 @@ return; | ||
case 4: { | ||
assert(++cnt === 10); | ||
assert(++cnt === 8); | ||
assert(data === 4); | ||
@@ -146,3 +146,3 @@ return; | ||
case 3: { | ||
assert(++cnt === 8); | ||
assert(++cnt === 7); | ||
assert(data === 3); | ||
@@ -152,3 +152,3 @@ return; | ||
case 4: { | ||
assert(++cnt === 11); | ||
assert(++cnt === 9); | ||
assert(data === 4); | ||
@@ -164,3 +164,3 @@ return; | ||
.monitor([], ([name, process, reason]) => { | ||
assert(++cnt === 6); | ||
assert(++cnt === 5); | ||
assert.deepStrictEqual(name, []); | ||
@@ -176,6 +176,6 @@ assert(process instanceof Function); | ||
assert(cnt === 0); | ||
sv.call([], 1, 0, r => assert(++cnt === 5) || assert.deepStrictEqual(r, [-1])); | ||
sv.call([], 1, 0).then(r => assert(++cnt === 10) || assert.deepStrictEqual(r, [-1])); | ||
assert.deepStrictEqual(sv.cast([], 2), [-2]); | ||
sv.call([], 3, 0, r => assert(++cnt === 9) || assert.deepStrictEqual(r, []) || assert(TestSupervisor.procs === 0)); | ||
sv.call([], 4, 0, r => assert(++cnt === 12) || assert.deepStrictEqual(r, []) || assert(TestSupervisor.procs === 0) || sv.terminate()); | ||
sv.call([], 3, 0).catch(_ => assert(++cnt === 11) || assert(TestSupervisor.procs === 0)); | ||
sv.call([], 4, 0).catch(_ => assert(++cnt === 12) || assert(TestSupervisor.procs === 0) || sv.terminate()); | ||
assert(++cnt === 3); | ||
@@ -249,3 +249,3 @@ }); | ||
sv.call([], 0, 0, r => { | ||
sv.call([], 0, 0).then(r => { | ||
assert.deepStrictEqual(r, [9, 10, 11, 12]); | ||
@@ -282,4 +282,4 @@ assert(cnt === 12); | ||
const sv = new class TestSupervisor extends Supervisor<string[], number, number> { }(); | ||
sv.call([], 1, 1e2, r => assert(++cnt === 2 && r.length === 0) || sv.terminate() || done()); | ||
sv.call([], 2, 0, r => assert(++cnt === 1 && r.length === 0)); | ||
sv.call([], 1, 1e2).catch(_ => assert(++cnt === 2) || sv.terminate() || done()); | ||
sv.call([], 2, 0).catch(_ => assert(++cnt === 1)); | ||
}); | ||
@@ -292,3 +292,3 @@ | ||
sv.register([], _ => ++cnt); | ||
sv.call([], 0, 0, _ => assert(cnt === 1) || sv.terminate() || done()); | ||
sv.call([], 0, 0).then(_ => assert(cnt === 1) || sv.terminate() || done()); | ||
assert(cnt === 0); | ||
@@ -310,6 +310,6 @@ }); | ||
sv.register([], n => new Promise<number>(resolve => void resolve(n))); | ||
sv.events.loss.on([], ([, data]) => assert(++cnt === 2 && data === 2)); | ||
sv.call([], 1, 0, r => assert(++cnt === 1 && r.length === 1) || r[0].then(n => assert(++cnt === 4 && n === 1))); | ||
sv.call([], 2, 0, r => assert(++cnt === 3 && r.length === 0)); | ||
sv.call([], 3, 1e9, r => assert(++cnt === 5 && r.length === 1) || sv.terminate() || done()); | ||
sv.events.loss.on([], ([, data]) => assert(++cnt === 1 && data === 2)); | ||
sv.call([], 1, 0).then(r => assert(++cnt === 2 && r.length === 1) || r[0].then(n => assert(++cnt === 4 && n === 1))); | ||
sv.call([], 2, 0).catch(_ => assert(++cnt === 3)); | ||
sv.call([], 3, 1e9).then(r => assert(++cnt === 5 && r.length === 1) || sv.terminate() || done()); | ||
}); | ||
@@ -330,15 +330,15 @@ | ||
sv.events.loss.monitor([], done); | ||
sv.call(['a'], 0, 1e9, r => assert(++cnt === 2 && r.length === 1)); | ||
sv.call(['b'], 0, 1e9, r => assert(++cnt === 9 && r.length === 1)); | ||
sv.call(['c'], 0, 1e9, r => assert(++cnt === 11 && r.length === 1) || sv.terminate() || done()); | ||
sv.call(['d'], 0, 1e9, r => assert(++cnt === 4 && r.length === 1)); | ||
sv.call(['e'], 0, 1e9, r => assert(++cnt === 6 && r.length === 1)); | ||
sv.call(['a'], 0, 1e9).then(r => assert(++cnt === 5 && r.length === 1)); | ||
sv.call(['b'], 0, 1e9).then(r => assert(++cnt === 10 && r.length === 1)); | ||
sv.call(['c'], 0, 1e9).then(r => assert(++cnt === 11 && r.length === 1) || sv.terminate() || done()); | ||
sv.call(['d'], 0, 1e9).then(r => assert(++cnt === 6 && r.length === 1)); | ||
sv.call(['e'], 0, 1e9).then(r => assert(++cnt === 7 && r.length === 1)); | ||
sv.register(['a'], _ => { | ||
sv.register(['d'], _ => assert(++cnt === 3)); | ||
sv.register(['d'], _ => assert(++cnt === 2)); | ||
sv.register(['b'], _ => assert(++cnt === 8)); | ||
assert(++cnt === 1); | ||
return new Promise<void>(resolve => void resolve(void 0)).then(_ => assert(++cnt === 7)); | ||
return new Promise<void>(resolve => void resolve(void 0)).then(_ => assert(++cnt === 4)); | ||
}); | ||
sv.register(['c'], _ => assert(++cnt === 10)); | ||
sv.register(['e'], _ => assert(++cnt === 5)); | ||
sv.register(['c'], _ => assert(++cnt === 9)); | ||
sv.register(['e'], _ => assert(++cnt === 3)); | ||
}); | ||
@@ -345,0 +345,0 @@ |
@@ -38,3 +38,3 @@ import {Supervisor as ISupervisor, SupervisorSettings} from 'spica'; | ||
this.name = name; | ||
void dependencies.reduce((_, [namespace, deps]) => void this.deps.set(namespace, deps), void 0); | ||
void dependencies.reduce<void>((_, [namespace, deps]) => void this.deps.set(namespace, deps), void 0); | ||
this.retry = retry; | ||
@@ -49,5 +49,5 @@ this.timeout = timeout; | ||
this.alive = false; | ||
assert(this.procs.refs(<T>[]).length === 0); | ||
assert(this.procs.refs(<T><any[]>[]).length === 0); | ||
while (this.queue.length > 0) { | ||
const [namespace, data] = this.queue.shift(); | ||
const [namespace, data] = this.queue.shift()!; | ||
void this.events.loss.emit(namespace, [namespace, data]); | ||
@@ -101,9 +101,20 @@ } | ||
} | ||
public call(namespace: T, data: D, timeout = this.timeout, callback: (results: R[], data: D) => any = noop): void { | ||
public call(namespace: T, data: D, timeout = this.timeout): Promise<R[]> { | ||
void this.checkState(); | ||
namespace = <T>concat([], namespace); | ||
void this.queue.push([namespace, data, (data, results) => void callback(results, data), timeout, Date.now()]); | ||
void this.schedule(); | ||
if (timeout > 0 === false) return; | ||
void setTimeout(() => this.drain(namespace), timeout); | ||
return new Promise<R[]>((resolve, reject) => { | ||
void this.queue.push([ | ||
namespace, | ||
data, | ||
results => | ||
results.length === 0 | ||
? void reject(data) | ||
: void resolve(results), | ||
timeout, | ||
Date.now() | ||
]); | ||
void this.schedule(); | ||
if (timeout > 0 === false) return; | ||
void setTimeout(() => void this.drain(namespace), timeout + 9); | ||
}); | ||
} | ||
@@ -121,4 +132,5 @@ public cast(namespace: T, data: D, retry = this.retry): R[] { | ||
return this.procs.refs(namespace) | ||
.map<[T, (data: D) => R, (reason: any) => void]>(([namespace, recv]) => { | ||
const worker: Worker<T, D, R> = <any>recv(void 0); | ||
.map<[T, (data: D) => R, (reason: any) => void]>(([, recv]) => { | ||
const worker: Worker<T, D, R> = <any>recv(new WorkerCommand.Self()); | ||
assert(worker instanceof Worker); | ||
return [ | ||
@@ -138,5 +150,5 @@ worker.namespace, | ||
void this.procs | ||
.emit(namespace || <T>[], new WorkerCommand.Exit(reason)); | ||
.emit(namespace || <T><any[]>[], new WorkerCommand.Exit(reason)); | ||
void this.procs | ||
.off(namespace || <T>[]); | ||
.off(namespace || <T><any[]>[]); | ||
if (namespace === void 0) { | ||
@@ -149,4 +161,4 @@ void this.destructor(reason); | ||
} | ||
private queue: [T, D, (data: D, results: R[]) => any, number, number][] = []; | ||
private drain(target: T = <T>[]): void { | ||
private queue: [T, D, (results: R[]) => void, number, number][] = []; | ||
private drain(target: T = <T><any[]>[]): void { | ||
const now = Date.now(); | ||
@@ -170,3 +182,3 @@ for (let i = 0; i < this.queue.length; ++i) { | ||
try { | ||
void callback(data, results); | ||
void callback(results); | ||
} | ||
@@ -182,3 +194,4 @@ catch (err) { | ||
type WorkerCommand<T, D> | ||
= WorkerCommand.Deps<T> | ||
= WorkerCommand.Self | ||
| WorkerCommand.Deps<T> | ||
| WorkerCommand.Call<D> | ||
@@ -190,3 +203,13 @@ | WorkerCommand.Exit; | ||
private WORKER_COMMAND: void; | ||
constructor() { | ||
void this.WORKER_COMMAND; | ||
} | ||
} | ||
export class Self extends AbstractCommand { | ||
private COMMAND: this; | ||
constructor() { | ||
super(); | ||
void this.COMMAND; | ||
} | ||
} | ||
export class Deps<T> extends AbstractCommand { | ||
@@ -196,2 +219,3 @@ private COMMAND: this; | ||
super(); | ||
void this.COMMAND; | ||
} | ||
@@ -203,2 +227,3 @@ } | ||
super(); | ||
void this.COMMAND; | ||
} | ||
@@ -210,2 +235,3 @@ } | ||
super(); | ||
void this.COMMAND; | ||
} | ||
@@ -223,3 +249,3 @@ } | ||
) { | ||
this.receive = (cmd?: WorkerCommand<T, D>) => Worker.prototype.receive.call(this, cmd); // identifier | ||
this.receive = (cmd: WorkerCommand<T, D>) => Worker.prototype.receive.call(this, cmd); // identifier | ||
this.terminate = (reason: any) => Worker.prototype.terminate.call(this, reason); | ||
@@ -256,8 +282,8 @@ | ||
} | ||
public receive(): Worker<T, D, R> | ||
public receive(cmd: WorkerCommand.Self): Worker<T, D, R> | ||
public receive(cmd: WorkerCommand.Deps<T>): boolean | ||
public receive(cmd: WorkerCommand<T, D>): R | ||
public receive(cmd?: WorkerCommand<T, D>): any { | ||
public receive(cmd: WorkerCommand<T, D>): any { | ||
void this.checkState(); | ||
if (cmd === void 0) { | ||
if (cmd instanceof WorkerCommand.Self) { | ||
return this; | ||
@@ -274,3 +300,3 @@ } | ||
.every(dep => | ||
(this.sharedResource.allRefsCache = this.sharedResource.allRefsCache || this.sharedResource.procs.refs(<T>[])) | ||
(this.sharedResource.allRefsCache = this.sharedResource.allRefsCache || this.sharedResource.procs.refs(<T><any[]>[])) | ||
.some(([ns, proc]) => equal(ns, dep) && !!proc(new WorkerCommand.Deps(dep))) | ||
@@ -277,0 +303,0 @@ ); |
@@ -1,4 +0,1 @@ | ||
declare let process: {}; | ||
declare let Promise: { resolve: <T>(val?: T) => PromiseLike<T> }; | ||
namespace TICK { | ||
@@ -20,3 +17,3 @@ export const queue = enqueue; | ||
while (task-- > 0) { | ||
void Queue.shift()(); | ||
void Queue.shift()!(); | ||
} | ||
@@ -23,0 +20,0 @@ } |
export function type(target: any): string { | ||
return (<string>Object.prototype.toString.call(target)).split(' ').pop().slice(0, -1); | ||
return (<string>Object.prototype.toString.call(target)).split(' ').pop()!.slice(0, -1); | ||
} |
import { | ||
Supervisor, SupervisorSettings, | ||
Supervisor, | ||
Observable, | ||
@@ -104,2 +104,6 @@ Sequence, | ||
describe('List', function () { | ||
it('List', function () { | ||
<List<number, Nil>>new Nil().push(0); | ||
}); | ||
it('Nil', function () { | ||
@@ -112,2 +116,6 @@ assert(typeof Nil === 'function'); | ||
describe('HList', function () { | ||
it('HList', function () { | ||
<HList<number, HNil>>new HNil().push(0); | ||
}); | ||
it('HNil', function () { | ||
@@ -190,3 +198,3 @@ assert(typeof HNil === 'function'); | ||
try { | ||
console.log(assert(false === true), assert); // LOG: undefined, function powerAssert() { ... } | ||
console.log(assert(!false === !true), assert); // LOG: undefined, function powerAssert() { ... } | ||
} | ||
@@ -193,0 +201,0 @@ catch (e) { |
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": [ | ||
"dom", | ||
"es6" | ||
], | ||
"module": "amd", | ||
"moduleResolution": "node", | ||
"allowSyntheticDefaultImports": true, | ||
"strictNullChecks": true, | ||
"noImplicitAny": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noUnusedParameters": true, | ||
"noUnusedLocals": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"preserveConstEnums": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"allowUnusedLabels": true, | ||
"preserveConstEnums": true, | ||
"rootDir": "./", | ||
"forceConsistentCasingInFileNames": true, | ||
"removeComments": false | ||
} | ||
}, | ||
"include": [ | ||
"*.ts", | ||
"src/**/*.ts", | ||
"test/**/*.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
389082
27
139
9728