Comparing version 0.0.8 to 0.0.9
@@ -1,3 +0,3 @@ | ||
/*! spica v0.0.8 https://github.com/falsandtru/spica | (c) 2016, falsandtru | undefined License (undefined) */ | ||
define="function"==typeof define&&define.amd?define:function(){"use strict";var e="spica",t={};return function n(r,i,o){return o?void o.apply(this,i.map(function(e){switch(e){case"require":return"function"==typeof require?require:void 0;case"exports":return-1===r.indexOf("/")?t[r]="undefined"==typeof exports?self[r]=self[r]||{}:exports:t[r]=t.hasOwnProperty(r)?t[r]:{};default:return".d"===e.slice(-2)&&{}||t.hasOwnProperty(e)&&t[e]||"function"==typeof require&&require(e)||self[e]}})):void n(e,r,i)}}();var __extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)};define("src/lib/concat",["require","exports"],function(e,t){"use strict";function n(e,t){for(var n=0,r=t.length,i=e.length;r>n;++n)e[n+i]=t[n];return e}t.concat=n}),define("src/lib/observable",["require","exports","src/lib/concat"],function(e,t,n){"use strict";var r=function(){function e(){this.node_={parent:void 0,childrenMap:Object.create(null),childrenList:[],registers:[]}}return e.prototype.monitor=function(e,t,n){var r=this;return void 0===n&&(n=t),void this.throwTypeErrorIfInvalidSubscriber_(t,e),void this.seekNode_(e).registers.push([e,n,!0,t]),function(){return r.off(e,n)}},e.prototype.on=function(e,t,n){var r=this;return void 0===n&&(n=t),void this.throwTypeErrorIfInvalidSubscriber_(t,e),void this.seekNode_(e).registers.push([e,n,!1,function(e){return t(e)}]),function(){return r.off(e,n)}},e.prototype.off=function(e,t){switch(typeof t){case"function":return void void this.seekNode_(e).registers.some(function(e,n,r){var i=e[1];if(t!==i)return!1;switch(n){case 0:return!void r.shift();case r.length-1:return!void r.pop();default:return!void r.splice(n,1)}});case"undefined":var n=this.seekNode_(e);return n.childrenMap=Object.create(null),n.childrenList=[],void(n.registers=[]);default:throw this.throwTypeErrorIfInvalidSubscriber_(t,e)}},e.prototype.once=function(e,t){var n=this;return void this.throwTypeErrorIfInvalidSubscriber_(t,e),this.on(e,function(r){return void n.off(e,t),t(r)},t)},e.prototype.emit=function(e,t,n){void this.drain_(e,t,n)},e.prototype.reflect=function(e,t){var n;return void this.emit(e,t,function(e,t){return n=t}),n},e.prototype.drain_=function(e,t,n){var r=[];if(void this.refsBelow_(this.seekNode_(e)).reduce(function(e,i){var o=i[2],u=i[3];if(!o)try{var c=u(t);n&&(r[r.length]=c)}catch(s){void 0!==s&&null!==s&&void console.error(s+"")}},void 0),void this.refsAbove_(this.seekNode_(e)).reduce(function(e,n){var r=n[2],i=n[3];if(r)try{void i(t)}catch(o){void 0!==o&&null!==o&&void console.error(o)}},void 0),n)try{void n(t,r)}catch(i){void console.error(i)}},e.prototype.refs=function(e){return this.refsBelow_(this.seekNode_(e))},e.prototype.refsAbove_=function(e){var t=e.parent,r=e.registers;for(r=n.concat([],r);t;)r=n.concat(r,t.registers),t=t.parent;return r},e.prototype.refsBelow_=function(e){var t=e.childrenList,r=e.childrenMap,i=e.registers;i=n.concat([],i);for(var o=0;o<t.length;++o){var u=t[o],c=this.refsBelow_(r[u]);i=n.concat(i,c),0===c.length&&(void delete r[u],void t.splice(t.indexOf(u),1),void--o)}return i},e.prototype.seekNode_=function(e){for(var t=this.node_,n=0,r=e;n<r.length;n++){var i=r[n],o=t.childrenMap;o[i+""]||(void t.childrenList.push(i+""),t.childrenList=t.childrenList.sort(),o[i+""]={parent:t,childrenMap:Object.create(null),childrenList:[],registers:[]}),t=o[i+""]}return t},e.prototype.throwTypeErrorIfInvalidSubscriber_=function(e,t){switch(typeof e){case"function":return;default:throw new TypeError("Spica: Observable: Invalid subscriber.\n "+e)}},e}();t.Observable=r}),define("src/lib/sqid",["require","exports"],function(e,t){"use strict";function n(e){return void 0===e?(1e15+ ++r+"").slice(1):(1e15+e+"").slice(1)}var r=0;t.sqid=n}),define("src/lib/type",["require","exports"],function(e,t){"use strict";function n(e){return Object.prototype.toString.call(e).split(" ").pop().slice(0,-1)}t.type=n}),define("src/lib/collection/datamap",["require","exports","src/lib/sqid","src/lib/type"],function(e,t,n,r){"use strict";function i(e){return e instanceof Object==!1}var o=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,n.sqid()))+" }"}},e.prototype.stringifyArray=function(e){for(var t="",n=0,r=e;n<r.length;n++){var i=r[n];t+=""+this.stringify(i)}return t},e.prototype.stringifyObject=function(e){if("Object"!==r.type(e))return"";for(var t=Object.keys(e),n="",i=0,o=t;i<o.length;i++){var u=o[i];n+=this.stringify(u)+": "+this.stringify(e[u])}return n||" "},e.prototype.get=function(e){return(this.store.get(this.stringify(e))||[])[1]},e.prototype.set=function(e,t){return void this.store.set(this.stringify(e),[e,t]),this},e.prototype.has=function(e){return this.store.has(this.stringify(e))},e.prototype["delete"]=function(e){return this.store["delete"](this.stringify(e))},e.prototype.clear=function(){return this.store.clear()},Object.defineProperty(e.prototype,"size",{get:function(){return this.store.size},enumerable:!0,configurable:!0}),e}();t.DataMap=o}),define("src/lib/tick",["require","exports"],function(e,t){"use strict";var n;!function(e){function t(e){void i.push(e),void r()}function n(){void r(),void--o;for(var e=i.length;e-- >0;)void i.shift()()}function r(){if(0!==i.length)for(;o<u.length;)void setTimeout(n,u[o%u.length]),void++o}e.queue=t;var i=[],o=0,u=[0,4,10,20,25].reverse()}(n||(n={}));var r=Function("return typeof process === 'object' && typeof window !== 'object'")();t.Tick=r?Function("return fn => process.nextTick(fn)")():n.queue}),define("src/lib/thenable",["require","exports"],function(e,t){"use strict";function n(e){return!!e&&"object"==typeof e&&void 0!==e.then}t.isThenable=n}),define("src/lib/noop",["require","exports"],function(e,t){"use strict";function n(){}t.noop=n}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/collection/datamap","src/lib/tick","src/lib/thenable","src/lib/concat","src/lib/noop"],function(e,t,n,r,i,o,u,c){"use strict";function s(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(var n=0;n<e.length;++n)if(e[n]!==t[n])return!1;return!0}var a=function(){function e(t){var i=this,o=void 0===t?{}:t,u=o.name,s=void 0===u?"":u,a=o.dependencies,f=void 0===a?[]:a,d=o.retry,l=void 0===d?!1:d,h=o.timeout,p=void 0===h?0:h,v=o.destructor,m=void 0===v?c.noop:v;if(this.deps=new r.DataMap,this.events={exec:new n.Observable,fail:new n.Observable,loss:new n.Observable,exit:new n.Observable},this.procs=new n.Observable,this.alive=!0,this.registerable=!0,this.scheduled=!1,this.workerSharedResource={procs:this.procs,dependenciesStack:[]},this.queue=[],this.constructor===e)throw new Error("Spica: Supervisor: Cannot instantiate abstract classes.");this.name=s,void f.reduce(function(e,t){var n=t[0],r=t[1];return void i.deps.set(n,r)},void 0),this.retry=l,this.timeout=p,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 t=this.queue.shift(),n=t[0],r=t[1];void this.events.loss.emit(n,[n,void 0,r])}try{void this.destructor_(e)}catch(i){void console.error(i)}void--this.constructor.count,void Object.freeze(this)},e.prototype.schedule=function(){var e=this;this.alive&&(this.scheduled||(void i.Tick(function(t){e.alive&&(e.scheduled=!1,void e.drain())}),this.scheduled=!0))},e.prototype.register=function(e,t){if(void this.checkState(),!this.registerable)throw new Error("Spica: Supervisor: Supervisor "+this.name+" cannot register process during the exiting.");return e=u.concat([],e),void this.schedule(),new d(this,this.workerSharedResource,e,t,this.deps.get(e)||[]).terminate},e.prototype.call=function(e,t,n,r){var i=this;void 0===n&&(n=this.timeout),void 0===r&&(r=c.noop),void this.checkState(),e=u.concat([],e),void this.queue.push([e,t,function(e,t){return void r(t,e)},n,Date.now()]),void this.schedule(),n>0!=!1&&void setTimeout(function(){return i.drain(e)},n)},e.prototype.cast=function(e,t,n){void 0===n&&(n=this.retry),void this.checkState();var r=this.procs.reflect(e,new f.Call(t));return 0===r.length&&void this.events.fail.emit(e,[e,void 0,t]),r.length>0||!n?r:this.cast(e,t,!1)},e.prototype.refs=function(e){return void this.checkState(),this.procs.refs(e).map(function(e){var t=(e[0],e[1]),n=t(void 0);return[n.namespace,n.process,n.terminate]})},e.prototype.terminate=function(e,t){void this.checkState(),void 0===e&&(this.registerable=!1),void this.procs.emit(e||[],new f.Exit(t)),void this.procs.off(e||[]),void 0===e&&void this.destructor(t)},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 t,n=Date.now(),r=function(r){var o=i.queue[r],u=o[0],c=o[1],s=o[2],a=o[3],d=o[4],l=e.every(function(e,t){return e===u[t]})?i.procs.reflect(u,new f.Call(c)):[];if(0===l.length&&void i.events.fail.emit(u,[u,void 0,c]),0===l.length&&d+a>n)return t=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(u,[u,void 0,c]),!s)return t=r,"continue";try{void s(c,l)}catch(h){void console.error(h)}t=r},i=this,o=0;o<this.queue.length;++o){r(o);o=t}},e.count=0,e.procs=0,e}();t.Supervisor=a;var f;!function(e){var t=function(){function e(){}return e}(),n=function(e){function t(t){e.call(this),this.namespace=t}return __extends(t,e),t}(t);e.Deps=n;var r=function(e){function t(t){e.call(this),this.data=t}return __extends(t,e),t}(t);e.Call=r;var i=function(e){function t(t){e.call(this),this.reason=t}return __extends(t,e),t}(t);e.Exit=i}(f||(f={}));var d=function(){function e(t,n,r,i,o){var u=this;this.sv=t,this.sharedResource=n,this.namespace=r,this.process=i,this.dependencies=o,this.alive=!0,this.called=!1,this.concurrency=1,this.receive=function(t){return e.prototype.receive.call(u,t)},this.terminate=function(t){return e.prototype.terminate.call(u,t)},this.sharedResource.allRefsCache=void 0,void++this.sv.constructor.procs,void this.sharedResource.procs.on(r,this.receive)}return e.prototype.destructor=function(e){void this.checkState(),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(e){if(this.receive(new f.Deps(this.namespace)))return void(this.sharedResource.dependenciesStack=[]);throw void(this.sharedResource.dependenciesStack=[])},e.prototype.receive=function(e){var t=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 n=0,r=this.sharedResource.dependenciesStack;n<r.length;n++){var i=r[n];if(s(this.namespace,i))return!0}return void this.sharedResource.dependenciesStack.push(this.namespace),this.dependencies.every(function(e){return(t.sharedResource.allRefsCache=t.sharedResource.allRefsCache||t.sharedResource.procs.refs([])).some(function(t){var n=t[0],r=t[1];return s(n,e)&&!!r(new f.Deps(e))})})}if(e instanceof f.Call){if(0===this.concurrency)throw void 0;void this.tryDependencyResolving(e),this.called||(this.called=!0,void this.sv.events.exec.emit(this.namespace,[this.namespace,this.process]));try{void--this.concurrency;var u=(0,this.process)(e.data);return o.isThenable(u)?void u.then(function(e){void t.sv.schedule(),t.alive&&void++t.concurrency},function(e){void t.sv.schedule(),t.alive&&(void++t.concurrency,void t.terminate(e))}):void++this.concurrency,u}catch(c){throw void void this.terminate(c)}}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,t){"use strict";var n=function(){function e(e){this.thunk=e}return e.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},e}();t.Lazy=n}),define("src/lib/monad/functor",["require","exports","src/lib/monad/lazy"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t}(n.Lazy);t.Functor=r}),define("src/lib/monad/monad",["require","exports","src/lib/monad/functor"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t}(n.Functor);t.Monad=r}),define("src/lib/monad/maybe.impl",["require","exports","src/lib/monad/monad"],function(e,t,n){"use strict";var r=function(e){function t(t){e.call(this,t),this.thunk=t}return __extends(t,e),t.prototype.bind=function(e){var n=this;return new t(function(){var r=n.evaluate();if(r instanceof i)return e(r.extract());if(r instanceof o)return r;if(r instanceof t)return r.bind(e);throw new TypeError("Spica: Maybe: Invalid monad value.\n "+r)})},t.prototype.fmap=function(e){return this.bind(function(t){return new i(e(t))})},t.prototype.extract=function(e){return this.evaluate().extract(e)},t}(n.Monad);t.Maybe=r;var i=function(e){function t(t){e.call(this),this.val_=t}return __extends(t,e),t.prototype.bind=function(e){var t=this;return new r(function(){return t}).bind(e)},t.prototype.extract=function(e){return this.val_},t}(r);t.Just=i;var o=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.bind=function(e){return this},t.prototype.fmap=function(e){return this},t.prototype.extract=function(e){if(!e)throw void 0;return e()},t}(r);t.Nothing=o}),define("src/lib/monad/maybe",["require","exports","src/lib/monad/maybe.impl"],function(e,t,n){"use strict";var r;!function(e){function t(e){return new n.Just(e)}e.Just=t,e.Nothing=new n.Nothing,e.Return=t}(r=t.Maybe||(t.Maybe={})),t.Just=r.Just,t.Nothing=r.Nothing,t.Return=t.Just}),define("src/lib/monad/either.impl",["require","exports","src/lib/monad/monad"],function(e,t,n){"use strict";var r=function(e){function t(t){e.call(this,t),this.thunk=t}return __extends(t,e),t.prototype.bind=function(e){var n=this;return new t(function(){var r=n.evaluate();if(r instanceof i)return r;if(r instanceof o)return e(r.extract());if(r instanceof t)return r.bind(e);throw new TypeError("Spica: Either: Invalid monad value.\n "+r)})},t.prototype.fmap=function(e){return this.bind(function(t){return new o(e(t))})},t.prototype.extract=function(e){return this.evaluate().extract(e)},t}(n.Monad);t.Either=r;var i=function(e){function t(t){e.call(this),this.val_=t}return __extends(t,e),t.prototype.bind=function(e){return this},t.prototype.fmap=function(e){return this},t.prototype.extract=function(e){if(!e)throw this.val_;return e(this.val_)},t}(r);t.Left=i;var o=function(e){function t(t){e.call(this),this.val_=t}return __extends(t,e),t.prototype.bind=function(e){var t=this;return new r(function(){return t}).bind(e)},t.prototype.extract=function(e){return this.val_},t}(r);t.Right=o}),define("src/lib/monad/either",["require","exports","src/lib/monad/either.impl"],function(e,t,n){"use strict";var r;!function(e){function t(e){return new n.Left(e)}function r(e){return new n.Right(e)}e.Left=t,e.Right=r,e.Return=r}(r=t.Either||(t.Either={})),t.Left=r.Left,t.Right=r.Right,t.Return=r.Return}),define("src/lib/cancelable",["require","exports","src/lib/noop","src/lib/monad/maybe","src/lib/monad/either"],function(e,t,n,r,i){"use strict";var o=function(){function e(){var e=this;this.canceled=!1,this.promise=function(t){return e.canceled?e.promise_=e.promise_||new Promise(function(t,n){return void n(e.reason)}):Promise.resolve(t)},this.maybe=function(t){return e.canceled?r.Nothing:r.Just(t)},this.either=function(t){return e.canceled?i.Left(e.reason):i.Right(t)},this.cancel=function(t){return e.cancel=n.noop,e.canceled=!0,void(e.reason=t)}}return e}();t.Cancelable=o}),define("src/lib/monad/sequence/core",["require","exports","src/lib/monad/monad"],function(e,t,n){"use strict";var r=function(e){function t(t,n){e.call(this),this.cons=t,this.memory=n}return __extends(t,e),t}(n.Monad);t.Sequence=r;var r;!function(e){}(r=t.Sequence||(t.Sequence={}));var r;!function(e){function t(e){return r.iterator(e)!==i.done}var n;!function(t){function n(t,n){switch(arguments.length){case 0:return[];case 1:return[t];case 2:return[t,n];default:throw e.Exception.invalidConsError(arguments)}}t.cons=n}(n=e.Data||(e.Data={}));var r;!function(e){function t(e){return e[0]}function n(e){return e[1]}function r(e){return e[2]}e.value=t,e.iterator=n,e.index=r}(r=e.Thunk||(e.Thunk={}));var i;!function(t){function n(t,i,o){return e.isIterable(t)?o(t,function(){return n(r.iterator(t)(),i,o)}):i(t)}t.done=function(){return[void 0,t.done,-1]},t.when=n}(i=e.Iterator||(e.Iterator={})),e.isIterable=t;var o;!function(e){function t(e){return console.error(e,e.length,e[0],e[1]),new TypeError("Spica: Sequence: Invalid parameters of cons.")}function n(e){return console.error(e),new TypeError("Spica: Sequence: Invalid data.")}function r(e){return console.error(e),new TypeError("Spica: Sequence: Invalid thunk.")}e.invalidConsError=t,e.invalidDataError=n,e.invalidThunkError=r}(o=e.Exception||(e.Exception={}))}(r=t.Sequence||(t.Sequence={}))}),define("src/lib/monad/sequence/member/static/from",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.from=function(e){return new n.Sequence(function(t,n){return void 0===t&&(t=0),t<e.length?n(e[t],++t):n()})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/write",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.write=function(e){return new n.Sequence(function(t,n){return e.length>0?n(e.shift(),e):n()})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/random",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.random=function(e){switch(void 0===e&&(e=function(){return Math.random()}),!0){case Array.isArray(e):return this.random().map(function(t){return e[t*e.length|0]});default:return new n.Sequence(function(t,n){return n(e(),NaN)})}},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/concat",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";function r(e,t){return new n.Sequence(function(r,i){var o=void 0===r?[function(){return e.iterate()},function(){return t.iterate()}]:r,u=o[0],c=o[1];return n.Sequence.Iterator.when(u(),function(){return n.Sequence.Iterator.when(c(),function(){return i()},function(e){return i(n.Sequence.Thunk.value(e),[n.Sequence.Iterator.done,n.Sequence.Thunk.iterator(e)])})},function(e){return i(n.Sequence.Thunk.value(e),[n.Sequence.Thunk.iterator(e),c])})})}var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.concat=function(e){return Array.isArray(e)?e.reduce(function(e,t){return r(e,t)},n.Sequence.from([])):e.bind(function(e){return Array.isArray(e)?n.Sequence.from(e):e})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/static/zip",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.zip=function(e,t){return new n.Sequence(function(r,i){var o=void 0===r?[function(){return e.iterate()},function(){return t.iterate()}]:r,u=o[0],c=o[1];return n.Sequence.Iterator.when(u(),function(){return i()},function(e){return n.Sequence.Iterator.when(c(),function(){return i()},function(t){return i([n.Sequence.Thunk.value(e),n.Sequence.Thunk.value(t)],[n.Sequence.Thunk.iterator(e),n.Sequence.Thunk.iterator(t)])})})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/union",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";function r(e,t,r){return new n.Sequence(function(i,o){var u=void 0===i?[function(){return t.iterate()},function(){return r.iterate()}]:i,c=u[0],s=u[1];return n.Sequence.Iterator.when(c(),function(){return n.Sequence.Iterator.when(s(),function(){return o()},function(e){return o(n.Sequence.Thunk.value(e),[n.Sequence.Iterator.done,n.Sequence.Thunk.iterator(e)])})},function(t){return n.Sequence.Iterator.when(s(),function(){return o(n.Sequence.Thunk.value(t),[n.Sequence.Thunk.iterator(t),n.Sequence.Iterator.done])},function(r){var i=e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.value(r));return 0>i?o(n.Sequence.Thunk.value(t),[n.Sequence.Thunk.iterator(t),s]):i>0?o(n.Sequence.Thunk.value(r),[c,n.Sequence.Thunk.iterator(r)]):o(n.Sequence.Thunk.value(t),[n.Sequence.Thunk.iterator(t),n.Sequence.Thunk.iterator(r)])})})})}var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.union=function(e,t){return t.reduce(function(t,n){return r(e,t,n)})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/static/intersect",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";function r(e,t,r){return new n.Sequence(function(i,o){var u=void 0===i?[function(){return t.iterate()},function(){return r.iterate()}]:i,c=u[0],s=u[1];return n.Sequence.Iterator.when(c(),function(){return o()},function(t,r){return n.Sequence.Iterator.when(s(),function(){return o()},function(i,u){var c=e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.value(i));return 0>c?(s=function(){return i},r()):c>0?u():o(n.Sequence.Thunk.value(t),[n.Sequence.Thunk.iterator(t),n.Sequence.Thunk.iterator(i)])})})})}var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.intersect=function(e,t){return t.reduce(function(t,n){return r(e,t,n)})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/instance/iterate",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.iterate=function(){return this.iterate_()},t.prototype.iterate_=function(e,t){var r=this;void 0===t&&(t=0);var i=this.memory?this.memory.has(t)?this.memory.get(t):this.memory.set(t,this.cons(e,n.Sequence.Data.cons)).get(t):this.cons(e,n.Sequence.Data.cons);switch(i.length){case 0:return[void 0,n.Sequence.Iterator.done,-1];case 1:return[i[0],function(){return n.Sequence.Iterator.done()},t];case 2:return[i[0],function(){return r.iterate_(i[1],t+1)},t];default:throw n.Sequence.Exception.invalidDataError(i)}},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/memoize",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.memoize=function(e){return void 0===e&&(e=this.memory||new Map),new n.Sequence(this.cons,this.memory||e)},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/read",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.read=function(){for(var e=this,t=[],i=function(){return e.iterate()};;){var o=i();if(!n.Sequence.isIterable(o))return t;void r.concat(t,[n.Sequence.Thunk.value(o)]),i=n.Sequence.Thunk.iterator(o)}},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/instance/take",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.take=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t){return n.Sequence.Thunk.index(t)<e?i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t)):i()})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/drop",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.drop=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return n.Sequence.Thunk.index(t)<e?r():i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/takeWhile",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.takeWhile=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t){return e(n.Sequence.Thunk.value(t))?i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t)):i()})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/dropWhile",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.dropWhile=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return e(n.Sequence.Thunk.value(t))?r():i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/takeUntil",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.takeUntil=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t){return e(n.Sequence.Thunk.value(t))?i(n.Sequence.Thunk.value(t)):i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/dropUntil",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.dropUntil=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return e(n.Sequence.Thunk.value(t))?r():i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/fmap",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.fmap=function(e){var t=this;return new n.Sequence(function(r){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return n.Sequence.Data.cons()},function(t){return n.Sequence.Data.cons(e(n.Sequence.Thunk.value(t)),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/bind",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.bind=function(e){var t=this;return new n.Sequence(function(r,i){var o=void 0===r?[function(){return t.iterate()},n.Sequence.Iterator.done]:r,u=o[0],c=o[1];return n.Sequence.Iterator.when(u(),function(){return i()},function(t,r){return c=c===n.Sequence.Iterator.done?function(){return e(n.Sequence.Thunk.value(t)).iterate()}:c,n.Sequence.Iterator.when(c(),function(){return c=n.Sequence.Iterator.done,r()},function(e){return i(n.Sequence.Thunk.value(e),[function(){return t},n.Sequence.Thunk.iterator(e)])})})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/mapM",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.mapM=function(e){var t=this;return this.take(1).bind(function(){var i=t.read();switch(i.length){case 0:return n.Sequence.from([]);default:var o=i.shift();return e(o).bind(function(t){return 0===i.length?n.Sequence.from([[t]]):n.Sequence.from(i).mapM(e).fmap(function(e){return r.concat([t],e)})})}})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/instance/filterM",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.filterM=function(e){var t=this;return this.take(1).bind(function(){var i=t.read();switch(i.length){case 0:return n.Sequence.from([[]]);default:var o=i.shift();return e(o).bind(function(t){return t?0===i.length?n.Sequence.from([[o]]):n.Sequence.from(i).filterM(e).fmap(function(e){return r.concat([o],e)}):0===i.length?n.Sequence.from([[]]):n.Sequence.from(i).filterM(e)})}})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/instance/map",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.map=function(e){var t=this;return new n.Sequence(function(r){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return n.Sequence.Data.cons()},function(t){return n.Sequence.Data.cons(e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.index(t)),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/filter",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.filter=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.index(t))?i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t)):r(); | ||
})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/scan",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.scan=function(e,t){var r=this;return new n.Sequence(function(i){var o=void 0===i?[void 0,void 0]:i,u=o[0],c=void 0===u?t:u,s=o[1],a=void 0===s?function(){return r.iterate()}:s;return n.Sequence.Iterator.when(a(),function(){return n.Sequence.Data.cons()},function(t){return n.Sequence.Data.cons(c=e(c,n.Sequence.Thunk.value(t)),[c,n.Sequence.Thunk.iterator(t)])})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/assign",["require","exports","src/lib/type"],function(e,t,n){"use strict";function r(e){return function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(void 0===t||null===t)throw new TypeError("Spica: assign: Cannot walk on "+t+".");for(var i=0,o=n;i<o.length;i++){var u=o[i];if(void 0!==u&&null!==u)for(var c=0,s=Object.keys(Object(u));c<s.length;c++){var a=s[c],f=Object.getOwnPropertyDescriptor(Object(u),a);void 0!==f&&f.enumerable&&void e(a,Object(t),Object(u))}}return Object(t)}}t.assign=r(function(e,t,n){return t[e]=n[e]}),t.clone=r(function(e,r,i){switch(n.type(i[e])){case"Array":return r[e]=t.clone([],i[e]);case"Function":case"Object":return r[e]=t.clone({},i[e]);default:return r[e]=i[e]}}),t.extend=r(function(e,r,i){switch(n.type(i[e])){case"Array":return r[e]=t.extend([],i[e]);case"Function":case"Object":switch(n.type(r[e])){case"Function":case"Object":return r[e]=t.extend(r[e],i[e]);default:return r[e]=t.extend({},i[e])}default:return r[e]=i[e]}})}),define("src/lib/compose",["require","exports","src/lib/assign","src/lib/concat"],function(e,t,n,r){"use strict";function i(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];return r.concat([e],t).reduce(function(e,t){void n.assign(e.prototype,t.prototype);for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e})}t.compose=i}),define("src/lib/monad/sequence",["require","exports","src/lib/monad/sequence/core","src/lib/monad/sequence/member/static/from","src/lib/monad/sequence/member/static/write","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/union","src/lib/monad/sequence/member/static/intersect","src/lib/monad/sequence/member/instance/iterate","src/lib/monad/sequence/member/instance/memoize","src/lib/monad/sequence/member/instance/read","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/compose"],function(e,t,n,r,i,o,u,c,s,a,f,d,l,h,p,v,m,b,q,y,S,x,w,_,g,k,T){"use strict";t.Sequence=n.Sequence,T.compose(n.Sequence,r["default"],i["default"],o["default"],u["default"],c["default"],s["default"],a["default"],f["default"],d["default"],l["default"],h["default"],p["default"],v["default"],m["default"],b["default"],q["default"],y["default"],S["default"],x["default"],w["default"],_["default"],g["default"],k["default"])}),define("src/lib/collection/attrmap",["require","exports"],function(e,t){"use strict";var n=function(){function e(){this.store=new WeakMap}return e.prototype.get=function(e,t){return this.store.get(e)&&this.store.get(e).get(t)},e.prototype.set=function(e,t,n){var r=this.store.has(e)?this.store.get(e):this.store.set(e,new Map).get(e);return void r.set(t,n),this},e.prototype.has=function(e,t){return this.store.has(e)&&this.store.get(e).has(t)},e.prototype["delete"]=function(e,t){return void 0===t?this.store["delete"](e):this.store.has(e)?this.store.get(e)["delete"](t):!1},e}();t.AttrMap=n}),define("src/lib/collection/relationmap",["require","exports"],function(e,t){"use strict";var n=function(){function e(){this.store=new WeakMap}return e.prototype.get=function(e,t){return this.store.get(e)&&this.store.get(e).get(t)},e.prototype.set=function(e,t,n){var r=this.store.has(e)?this.store.get(e):this.store.set(e,new WeakMap).get(e);return void r.set(t,n),this},e.prototype.has=function(e,t){return this.store.has(e)&&this.store.get(e).has(t)},e.prototype["delete"]=function(e,t){return void 0===t?this.store["delete"](e):this.store.has(e)?this.store.get(e)["delete"](t):!1},e}();t.RelationMap=n}),define("src/lib/mixin",["require","exports","src/lib/assign"],function(e,t,n){"use strict";function r(){for(var e=[],t=0;t<arguments.length;t++)e[t-0]=arguments[t];return e.reduceRight(function(e,t){return i(t,e)},function(){function e(){}return e}())}function i(e,t){var r=function(){function n(){return e.apply(t.apply(this,arguments)||this,arguments)}return n}();void n.assign(r.prototype,e.prototype,t.prototype);for(var i in t)t.hasOwnProperty(i)&&(r[i]=t[i]);for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);return r}t.Mixin=r}),define("src/lib/fingerprint",["require","exports"],function(e,t){"use strict";function n(){return i(o([u(window.navigator),u(window.screen),u((new Date).getTimezoneOffset())].join()))}function r(){return i(o([u(process)].join()))}function i(e){return e.split("").reduce(function(e,t,n){return(+t*n+e)%1e9||e-+t},0)}function o(e){return e.split("").map(function(e){return e.charCodeAt(0)}).join("")}function u(e,t){if(void 0===t&&(t=5),t>0&&e&&"object"==typeof e){var n="{";for(var r in e)n+='"'+r+'": '+u(e[r],t-1)+",";return n+="}"}return!e||e.toString?'"'+e+'"':'"'+Object.prototype.toString.call(e)+'"'}t.FINGERPRINT="object"==typeof window?n():r(),t.browser=n,t.server=r,t.hash=i,t.str2digit=o,t.stringify=u}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(e,t,n){"use strict";function r(){var e=u=u*Date.now()%1e15;if(16>e||e>1e15)throw new Error("Spica: uuid: Invalid uuid dynamic seed.");for(var t="",n=0,r=o;n<r.length;n++){var i=r[n];if("x"===i||"y"===i){var c=Math.random()*e%16|0,s="x"==i?c:3&c|8;t+=s.toString(16)}else t+=i}return t.toLowerCase()}var i=n.FINGERPRINT*Date.now()%1e15;if(!i||"number"!=typeof i||100>i||i>1e15)throw new Error("Spica: uuid: Invalid uuid static seed.\n "+n.FINGERPRINT);var o=Object.freeze("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split("")),u=i;t.v4=r}),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/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"],function(e,t,n,r,i,o,u,c,s,a,f,d,l,h,p,v,m,b){"use strict";t.Supervisor=n.Supervisor,t.Observable=r.Observable,t.Cancelable=i.Cancelable,t.Sequence=o.Sequence,t.Maybe=u.Maybe,t.Just=u.Just,t.Nothing=u.Nothing,t.Either=c.Either,t.Left=c.Left,t.Right=c.Right,t.DataMap=s.DataMap,t.AttrMap=a.AttrMap,t.RelationMap=f.RelationMap,t.Mixin=d.Mixin,t.Tick=l.Tick,t.FINGERPRINT=h.FINGERPRINT,t.uuid=p.v4,t.sqid=v.sqid,t.assign=m.assign,t.clone=m.clone,t.extend=m.extend,t.concat=b.concat}),define("spica",["require","exports","src/export"],function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}r(n)}); | ||
/*! spica v0.0.9 https://github.com/falsandtru/spica | (c) 2016, falsandtru | undefined License (undefined) */ | ||
define="function"==typeof define&&define.amd?define:function(){"use strict";var e="spica",t={};return function n(r,i,o){return o?void o.apply(this,i.map(function(e){switch(e){case"require":return"function"==typeof require?require:void 0;case"exports":return-1===r.indexOf("/")?t[r]="undefined"==typeof exports?self[r]=self[r]||{}:exports:t[r]=t.hasOwnProperty(r)?t[r]:{};default:return".d"===e.slice(-2)&&{}||t.hasOwnProperty(e)&&t[e]||"function"==typeof require&&require(e)||self[e]}})):void n(e,r,i)}}();var __extends=this&&this.__extends||function(e,t){function n(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)};define("src/lib/concat",["require","exports"],function(e,t){"use strict";function n(e,t){for(var n=0,r=t.length,i=e.length;r>n;++n)e[n+i]=t[n];return e}t.concat=n}),define("src/lib/observable",["require","exports","src/lib/concat"],function(e,t,n){"use strict";var r=function(){function e(){this.node_={parent:void 0,childrenMap:Object.create(null),childrenList:[],registers:[]}}return e.prototype.monitor=function(e,t,n){var r=this;return void 0===n&&(n=t),void this.throwTypeErrorIfInvalidSubscriber_(t,e),void this.seekNode_(e).registers.push([e,n,!0,t]),function(){return r.off(e,n)}},e.prototype.on=function(e,t,n){var r=this;return void 0===n&&(n=t),void this.throwTypeErrorIfInvalidSubscriber_(t,e),void this.seekNode_(e).registers.push([e,n,!1,function(e){return t(e)}]),function(){return r.off(e,n)}},e.prototype.off=function(e,t){switch(typeof t){case"function":return void void this.seekNode_(e).registers.some(function(e,n,r){var i=e[1];if(t!==i)return!1;switch(n){case 0:return!void r.shift();case r.length-1:return!void r.pop();default:return!void r.splice(n,1)}});case"undefined":var n=this.seekNode_(e);return n.childrenMap=Object.create(null),n.childrenList=[],void(n.registers=[]);default:throw this.throwTypeErrorIfInvalidSubscriber_(t,e)}},e.prototype.once=function(e,t){var n=this;return void this.throwTypeErrorIfInvalidSubscriber_(t,e),this.on(e,function(r){return void n.off(e,t),t(r)},t)},e.prototype.emit=function(e,t,n){void this.drain_(e,t,n)},e.prototype.reflect=function(e,t){var n;return void this.emit(e,t,function(e,t){return n=t}),n},e.prototype.drain_=function(e,t,n){var r=[];if(void this.refsBelow_(this.seekNode_(e)).reduce(function(e,i){var o=i[2],u=i[3];if(!o)try{var c=u(t);n&&(r[r.length]=c)}catch(s){void 0!==s&&null!==s&&void console.error(s+"")}},void 0),void this.refsAbove_(this.seekNode_(e)).reduce(function(e,n){var r=n[2],i=n[3];if(r)try{void i(t)}catch(o){void 0!==o&&null!==o&&void console.error(o)}},void 0),n)try{void n(t,r)}catch(i){void console.error(i)}},e.prototype.refs=function(e){return this.refsBelow_(this.seekNode_(e))},e.prototype.refsAbove_=function(e){var t=e.parent,r=e.registers;for(r=n.concat([],r);t;)r=n.concat(r,t.registers),t=t.parent;return r},e.prototype.refsBelow_=function(e){var t=e.childrenList,r=e.childrenMap,i=e.registers;i=n.concat([],i);for(var o=0;o<t.length;++o){var u=t[o],c=this.refsBelow_(r[u]);i=n.concat(i,c),0===c.length&&(void delete r[u],void t.splice(t.indexOf(u),1),void--o)}return i},e.prototype.seekNode_=function(e){for(var t=this.node_,n=0,r=e;n<r.length;n++){var i=r[n],o=t.childrenMap;o[i+""]||(void t.childrenList.push(i+""),t.childrenList=t.childrenList.sort(),o[i+""]={parent:t,childrenMap:Object.create(null),childrenList:[],registers:[]}),t=o[i+""]}return t},e.prototype.throwTypeErrorIfInvalidSubscriber_=function(e,t){switch(typeof e){case"function":return;default:throw new TypeError("Spica: Observable: Invalid subscriber.\n "+e)}},e}();t.Observable=r}),define("src/lib/sqid",["require","exports"],function(e,t){"use strict";function n(e){return void 0===e?(1e15+ ++r+"").slice(1):(1e15+e+"").slice(1)}var r=0;t.sqid=n}),define("src/lib/type",["require","exports"],function(e,t){"use strict";function n(e){return Object.prototype.toString.call(e).split(" ").pop().slice(0,-1)}t.type=n}),define("src/lib/collection/datamap",["require","exports","src/lib/sqid","src/lib/type"],function(e,t,n,r){"use strict";function i(e){return e instanceof Object==!1}var o=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,n.sqid()))+" }"}},e.prototype.stringifyArray=function(e){for(var t="",n=0,r=e;n<r.length;n++){var i=r[n];t+=""+this.stringify(i)}return t},e.prototype.stringifyObject=function(e){if("Object"!==r.type(e))return"";for(var t=Object.keys(e),n="",i=0,o=t;i<o.length;i++){var u=o[i];n+=this.stringify(u)+": "+this.stringify(e[u])}return n||" "},e.prototype.get=function(e){return(this.store.get(this.stringify(e))||[])[1]},e.prototype.set=function(e,t){return void this.store.set(this.stringify(e),[e,t]),this},e.prototype.has=function(e){return this.store.has(this.stringify(e))},e.prototype["delete"]=function(e){return this.store["delete"](this.stringify(e))},e.prototype.clear=function(){return this.store.clear()},Object.defineProperty(e.prototype,"size",{get:function(){return this.store.size},enumerable:!0,configurable:!0}),e}();t.DataMap=o}),define("src/lib/tick",["require","exports"],function(e,t){"use strict";var n;!function(e){function t(e){void i.push(e),void r()}function n(){void r(),void--o;for(var e=i.length;e-- >0;)void i.shift()()}function r(){if(0!==i.length)for(;o<u.length;)void setTimeout(n,u[o%u.length]),void++o}e.queue=t;var i=[],o=0,u=[0,4,10,20,25].reverse()}(n||(n={}));var r=Function("return typeof process === 'object' && typeof window !== 'object'")();t.Tick=r?Function("return fn => process.nextTick(fn)")():n.queue}),define("src/lib/thenable",["require","exports"],function(e,t){"use strict";function n(e){return!!e&&"object"==typeof e&&void 0!==e.then}t.isThenable=n}),define("src/lib/noop",["require","exports"],function(e,t){"use strict";function n(){}t.noop=n}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/collection/datamap","src/lib/tick","src/lib/thenable","src/lib/concat","src/lib/noop"],function(e,t,n,r,i,o,u,c){"use strict";function s(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(var n=0;n<e.length;++n)if(e[n]!==t[n])return!1;return!0}var a=function(){function e(t){var i=this,o=void 0===t?{}:t,u=o.name,s=void 0===u?"":u,a=o.dependencies,f=void 0===a?[]:a,d=o.retry,l=void 0===d?!1:d,h=o.timeout,p=void 0===h?0:h,v=o.destructor,m=void 0===v?c.noop:v;if(this.deps=new r.DataMap,this.events={exec:new n.Observable,fail:new n.Observable,loss:new n.Observable,exit:new n.Observable},this.procs=new n.Observable,this.alive=!0,this.registerable=!0,this.scheduled=!1,this.workerSharedResource={procs:this.procs,dependenciesStack:[]},this.queue=[],this.constructor===e)throw new Error("Spica: Supervisor: Cannot instantiate abstract classes.");this.name=s,void f.reduce(function(e,t){var n=t[0],r=t[1];return void i.deps.set(n,r)},void 0),this.retry=l,this.timeout=p,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 t=this.queue.shift(),n=t[0],r=t[1];void this.events.loss.emit(n,[n,void 0,r])}try{void this.destructor_(e)}catch(i){void console.error(i)}void--this.constructor.count,void Object.freeze(this)},e.prototype.schedule=function(){var e=this;this.alive&&(this.scheduled||(void i.Tick(function(t){e.alive&&(e.scheduled=!1,void e.drain())}),this.scheduled=!0))},e.prototype.register=function(e,t){if(void this.checkState(),!this.registerable)throw new Error("Spica: Supervisor: Supervisor "+this.name+" cannot register process during the exiting.");return e=u.concat([],e),void this.schedule(),new d(this,this.workerSharedResource,e,t,this.deps.get(e)||[]).terminate},e.prototype.call=function(e,t,n,r){var i=this;void 0===n&&(n=this.timeout),void 0===r&&(r=c.noop),void this.checkState(),e=u.concat([],e),void this.queue.push([e,t,function(e,t){return void r(t,e)},n,Date.now()]),void this.schedule(),n>0!=!1&&void setTimeout(function(){return i.drain(e)},n)},e.prototype.cast=function(e,t,n){void 0===n&&(n=this.retry),void this.checkState();var r=this.procs.reflect(e,new f.Call(t));return 0===r.length&&void this.events.fail.emit(e,[e,void 0,t]),r.length>0||!n?r:this.cast(e,t,!1)},e.prototype.refs=function(e){return void this.checkState(),this.procs.refs(e).map(function(e){var t=(e[0],e[1]),n=t(void 0);return[n.namespace,n.process,n.terminate]})},e.prototype.terminate=function(e,t){void this.checkState(),void 0===e&&(this.registerable=!1),void this.procs.emit(e||[],new f.Exit(t)),void this.procs.off(e||[]),void 0===e&&void this.destructor(t)},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 t,n=Date.now(),r=function(r){var o=i.queue[r],u=o[0],c=o[1],s=o[2],a=o[3],d=o[4],l=e.every(function(e,t){return e===u[t]})?i.procs.reflect(u,new f.Call(c)):[];if(0===l.length&&void i.events.fail.emit(u,[u,void 0,c]),0===l.length&&d+a>n)return t=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(u,[u,void 0,c]),!s)return t=r,"continue";try{void s(c,l)}catch(h){void console.error(h)}t=r},i=this,o=0;o<this.queue.length;++o){r(o);o=t}},e.count=0,e.procs=0,e}();t.Supervisor=a;var f;!function(e){var t=function(){function e(){}return e}(),n=function(e){function t(t){e.call(this),this.namespace=t}return __extends(t,e),t}(t);e.Deps=n;var r=function(e){function t(t){e.call(this),this.data=t}return __extends(t,e),t}(t);e.Call=r;var i=function(e){function t(t){e.call(this),this.reason=t}return __extends(t,e),t}(t);e.Exit=i}(f||(f={}));var d=function(){function e(t,n,r,i,o){var u=this;this.sv=t,this.sharedResource=n,this.namespace=r,this.process=i,this.dependencies=o,this.alive=!0,this.called=!1,this.concurrency=1,this.receive=function(t){return e.prototype.receive.call(u,t)},this.terminate=function(t){return e.prototype.terminate.call(u,t)},this.sharedResource.allRefsCache=void 0,void++this.sv.constructor.procs,void this.sharedResource.procs.on(r,this.receive)}return e.prototype.destructor=function(e){void this.checkState(),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(e){if(this.receive(new f.Deps(this.namespace)))return void(this.sharedResource.dependenciesStack=[]);throw void(this.sharedResource.dependenciesStack=[])},e.prototype.receive=function(e){var t=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 n=0,r=this.sharedResource.dependenciesStack;n<r.length;n++){var i=r[n];if(s(this.namespace,i))return!0}return void this.sharedResource.dependenciesStack.push(this.namespace),this.dependencies.every(function(e){return(t.sharedResource.allRefsCache=t.sharedResource.allRefsCache||t.sharedResource.procs.refs([])).some(function(t){var n=t[0],r=t[1];return s(n,e)&&!!r(new f.Deps(e))})})}if(e instanceof f.Call){if(0===this.concurrency)throw void 0;void this.tryDependencyResolving(e),this.called||(this.called=!0,void this.sv.events.exec.emit(this.namespace,[this.namespace,this.process]));try{void--this.concurrency;var u=(0,this.process)(e.data);return o.isThenable(u)?void u.then(function(e){void t.sv.schedule(),t.alive&&void++t.concurrency},function(e){void t.sv.schedule(),t.alive&&(void++t.concurrency,void t.terminate(e))}):void++this.concurrency,u}catch(c){throw void void this.terminate(c)}}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,t){"use strict";var n=function(){function e(e){this.thunk=e}return e.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},e}();t.Lazy=n}),define("src/lib/monad/functor",["require","exports","src/lib/monad/lazy"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t}(n.Lazy);t.Functor=r}),define("src/lib/monad/monad",["require","exports","src/lib/monad/functor"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t}(n.Functor);t.Monad=r}),define("src/lib/monad/maybe.impl",["require","exports","src/lib/monad/monad"],function(e,t,n){"use strict";var r=function(e){function t(t){e.call(this,t),this.thunk=t}return __extends(t,e),t.prototype.bind=function(e){var n=this;return new t(function(){var r=n.evaluate();if(r instanceof i)return e(r.extract());if(r instanceof o)return r;if(r instanceof t)return r.bind(e);throw new TypeError("Spica: Maybe: Invalid monad value.\n "+r)})},t.prototype.fmap=function(e){return this.bind(function(t){return new i(e(t))})},t.prototype.extract=function(e){return this.evaluate().extract(e)},t}(n.Monad);t.Maybe=r;var i=function(e){function t(t){e.call(this),this.val_=t}return __extends(t,e),t.prototype.bind=function(e){var t=this;return new r(function(){return t}).bind(e)},t.prototype.extract=function(e){return this.val_},t}(r);t.Just=i;var o=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.bind=function(e){return this},t.prototype.fmap=function(e){return this},t.prototype.extract=function(e){if(!e)throw void 0;return e()},t}(r);t.Nothing=o}),define("src/lib/monad/maybe",["require","exports","src/lib/monad/maybe.impl"],function(e,t,n){"use strict";var r;!function(e){function t(e){return new n.Just(e)}e.Just=t,e.Nothing=new n.Nothing,e.Return=t}(r=t.Maybe||(t.Maybe={})),t.Just=r.Just,t.Nothing=r.Nothing,t.Return=t.Just}),define("src/lib/monad/either.impl",["require","exports","src/lib/monad/monad"],function(e,t,n){"use strict";var r=function(e){function t(t){e.call(this,t),this.thunk=t}return __extends(t,e),t.prototype.bind=function(e){var n=this;return new t(function(){var r=n.evaluate();if(r instanceof i)return r;if(r instanceof o)return e(r.extract());if(r instanceof t)return r.bind(e);throw new TypeError("Spica: Either: Invalid monad value.\n "+r)})},t.prototype.fmap=function(e){return this.bind(function(t){return new o(e(t))})},t.prototype.extract=function(e){return this.evaluate().extract(e)},t}(n.Monad);t.Either=r;var i=function(e){function t(t){e.call(this),this.val_=t}return __extends(t,e),t.prototype.bind=function(e){return this},t.prototype.fmap=function(e){return this},t.prototype.extract=function(e){if(!e)throw this.val_;return e(this.val_)},t}(r);t.Left=i;var o=function(e){function t(t){e.call(this),this.val_=t}return __extends(t,e),t.prototype.bind=function(e){var t=this;return new r(function(){return t}).bind(e)},t.prototype.extract=function(e){return this.val_},t}(r);t.Right=o}),define("src/lib/monad/either",["require","exports","src/lib/monad/either.impl"],function(e,t,n){"use strict";var r;!function(e){function t(e){return new n.Left(e)}function r(e){return new n.Right(e)}e.Left=t,e.Right=r,e.Return=r}(r=t.Either||(t.Either={})),t.Left=r.Left,t.Right=r.Right,t.Return=r.Return}),define("src/lib/cancelable",["require","exports","src/lib/noop","src/lib/monad/maybe","src/lib/monad/either"],function(e,t,n,r,i){"use strict";var o=function(){function e(){var e=this;this.canceled=!1,this.promise=function(t){return e.canceled?e.promise_=e.promise_||new Promise(function(t,n){return void n(e.reason)}):Promise.resolve(t)},this.maybe=function(t){return e.canceled?r.Nothing:r.Just(t)},this.either=function(t){return e.canceled?i.Left(e.reason):i.Right(t)},this.cancel=function(t){return e.cancel=n.noop,e.canceled=!0,void(e.reason=t)}}return e}();t.Cancelable=o}),define("src/lib/monad/sequence/core",["require","exports","src/lib/monad/monad"],function(e,t,n){"use strict";var r=function(e){function t(t,n){e.call(this),this.cons=t,this.memory=n}return __extends(t,e),t}(n.Monad);t.Sequence=r;var r;!function(e){}(r=t.Sequence||(t.Sequence={}));var r;!function(e){function t(e){return r.iterator(e)!==i.done}var n;!function(t){function n(t,n){switch(arguments.length){case 0:return[];case 1:return[t];case 2:return[t,n];default:throw e.Exception.invalidConsError(arguments)}}t.cons=n}(n=e.Data||(e.Data={}));var r;!function(e){function t(e){return e[0]}function n(e){return e[1]}function r(e){return e[2]}e.value=t,e.iterator=n,e.index=r}(r=e.Thunk||(e.Thunk={}));var i;!function(t){function n(t,i,o){return e.isIterable(t)?o(t,function(){return n(r.iterator(t)(),i,o)}):i(t)}t.done=function(){return[void 0,t.done,-1]},t.when=n}(i=e.Iterator||(e.Iterator={})),e.isIterable=t;var o;!function(e){function t(e){return console.error(e,e.length,e[0],e[1]),new TypeError("Spica: Sequence: Invalid parameters of cons.")}function n(e){return console.error(e),new TypeError("Spica: Sequence: Invalid data.")}function r(e){return console.error(e),new TypeError("Spica: Sequence: Invalid thunk.")}e.invalidConsError=t,e.invalidDataError=n,e.invalidThunkError=r}(o=e.Exception||(e.Exception={}))}(r=t.Sequence||(t.Sequence={}))}),define("src/lib/monad/sequence/member/static/from",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.from=function(e){return new n.Sequence(function(t,n){return void 0===t&&(t=0),t<e.length?n(e[t],++t):n()})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/write",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.write=function(e){return new n.Sequence(function(t,n){return e.length>0?n(e.shift(),e):n()})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/random",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.random=function(e){switch(void 0===e&&(e=function(){return Math.random()}),!0){case Array.isArray(e):return this.random().map(function(t){return e[t*e.length|0]});default:return new n.Sequence(function(t,n){return n(e(),NaN)})}},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/concat",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.concat=function(e){return Array.isArray(e)?n.Sequence.mconcat(e):e.bind(function(e){return Array.isArray(e)?n.Sequence.from(e):e})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/zip",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.zip=function(e,t){return new n.Sequence(function(r,i){var o=void 0===r?[function(){return e.iterate()},function(){return t.iterate()}]:r,u=o[0],c=o[1];return n.Sequence.Iterator.when(u(),function(){return i()},function(e){return n.Sequence.Iterator.when(c(),function(){return i()},function(t){return i([n.Sequence.Thunk.value(e),n.Sequence.Thunk.value(t)],[n.Sequence.Thunk.iterator(e),n.Sequence.Thunk.iterator(t)])})})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/union",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";function r(e,t,r){return new n.Sequence(function(i,o){var u=void 0===i?[function(){return t.iterate()},function(){return r.iterate()}]:i,c=u[0],s=u[1];return n.Sequence.Iterator.when(c(),function(){return n.Sequence.Iterator.when(s(),function(){return o()},function(e){return o(n.Sequence.Thunk.value(e),[n.Sequence.Iterator.done,n.Sequence.Thunk.iterator(e)])})},function(t){return n.Sequence.Iterator.when(s(),function(){return o(n.Sequence.Thunk.value(t),[n.Sequence.Thunk.iterator(t),n.Sequence.Iterator.done])},function(r){var i=e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.value(r));return 0>i?o(n.Sequence.Thunk.value(t),[n.Sequence.Thunk.iterator(t),s]):i>0?o(n.Sequence.Thunk.value(r),[c,n.Sequence.Thunk.iterator(r)]):o(n.Sequence.Thunk.value(t),[n.Sequence.Thunk.iterator(t),n.Sequence.Thunk.iterator(r)])})})})}var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.union=function(e,t){return t.reduce(function(t,n){return r(e,t,n)})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/static/intersect",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";function r(e,t,r){return new n.Sequence(function(i,o){var u=void 0===i?[function(){return t.iterate()},function(){return r.iterate()}]:i,c=u[0],s=u[1];return n.Sequence.Iterator.when(c(),function(){return o()},function(t,r){return n.Sequence.Iterator.when(s(),function(){return o()},function(i,u){var c=e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.value(i));return 0>c?(s=function(){return i},r()):c>0?u():o(n.Sequence.Thunk.value(t),[n.Sequence.Thunk.iterator(t),n.Sequence.Thunk.iterator(i)])})})})}var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.intersect=function(e,t){return t.reduce(function(t,n){return r(e,t,n)})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/static/return",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.Return=function(e){return new n.Sequence(function(t,n){return n(e)})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/mempty",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.mempty=new n.Sequence(function(e,t){return t()}),t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/static/mconcat",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";function r(e,t){return new n.Sequence(function(r,i){var o=void 0===r?[function(){return e.iterate()},function(){return t.iterate()}]:r,u=o[0],c=o[1];return n.Sequence.Iterator.when(u(),function(){return n.Sequence.Iterator.when(c(),function(){return i()},function(e){return i(n.Sequence.Thunk.value(e),[n.Sequence.Iterator.done,n.Sequence.Thunk.iterator(e)])})},function(e){return i(n.Sequence.Thunk.value(e),[n.Sequence.Thunk.iterator(e),c])})})}var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.mconcat=function(e){return e.reduce(function(e,t){return r(e,t)},n.Sequence.from([]))},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/static/mappend",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.mappend=function(e,t){return n.Sequence.mconcat([e,t])},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/iterate",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.iterate=function(){return this.iterate_()},t.prototype.iterate_=function(e,t){var r=this;void 0===t&&(t=0);var i=this.memory?this.memory.has(t)?this.memory.get(t):this.memory.set(t,this.cons(e,n.Sequence.Data.cons)).get(t):this.cons(e,n.Sequence.Data.cons);switch(i.length){case 0:return[void 0,n.Sequence.Iterator.done,-1];case 1:return[i[0],function(){return n.Sequence.Iterator.done()},t];case 2:return[i[0],function(){return r.iterate_(i[1],t+1)},t];default:throw n.Sequence.Exception.invalidDataError(i)}},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/memoize",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.memoize=function(e){return void 0===e&&(e=this.memory||new Map),new n.Sequence(this.cons,this.memory||e)},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/read",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.read=function(){for(var e=this,t=[],i=function(){return e.iterate()};;){var o=i();if(!n.Sequence.isIterable(o))return t;void r.concat(t,[n.Sequence.Thunk.value(o)]),i=n.Sequence.Thunk.iterator(o)}},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/instance/take",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.take=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(e>0?r():n.Sequence.Iterator.done(),function(){return i()},function(t){return n.Sequence.Thunk.index(t)+1<e?i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t)):i(n.Sequence.Thunk.value(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/drop",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.drop=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return n.Sequence.Thunk.index(t)<e?r():i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/takeWhile",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.takeWhile=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t){return e(n.Sequence.Thunk.value(t))?i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t)):i()})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/dropWhile",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.dropWhile=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return e(n.Sequence.Thunk.value(t))?r():i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/takeUntil",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.takeUntil=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t){return e(n.Sequence.Thunk.value(t))?i(n.Sequence.Thunk.value(t)):i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/dropUntil",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.dropUntil=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return e(n.Sequence.Thunk.value(t))?r():i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/fmap",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.fmap=function(e){var t=this;return new n.Sequence(function(r){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return n.Sequence.Data.cons()},function(t){return n.Sequence.Data.cons(e(n.Sequence.Thunk.value(t)),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/bind",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.bind=function(e){var t=this;return new n.Sequence(function(r,i){var o=void 0===r?[function(){return t.iterate()},n.Sequence.Iterator.done]:r,u=o[0],c=o[1];return n.Sequence.Iterator.when(u(),function(){return i()},function(t,r){return c=c===n.Sequence.Iterator.done?function(){return e(n.Sequence.Thunk.value(t)).iterate()}:c,n.Sequence.Iterator.when(c(),function(){return c=n.Sequence.Iterator.done,r()},function(e){return i(n.Sequence.Thunk.value(e),[function(){return t},n.Sequence.Thunk.iterator(e)])})})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/mapM",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.mapM=function(e){var t=this;return this.take(1).bind(function(){var i=t.read();switch(i.length){case 0:return n.Sequence.from([]);default:var o=i.shift();return e(o).bind(function(t){return 0===i.length?n.Sequence.from([[t]]):n.Sequence.from(i).mapM(e).fmap(function(e){return r.concat([t],e)})})}})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/instance/filterM",["require","exports","src/lib/monad/sequence/core","src/lib/concat"],function(e,t,n,r){"use strict";var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.filterM=function(e){var t=this;return this.take(1).bind(function(){var i=t.read();switch(i.length){ | ||
case 0:return n.Sequence.from([[]]);default:var o=i.shift();return e(o).bind(function(t){return t?0===i.length?n.Sequence.from([[o]]):n.Sequence.from(i).filterM(e).fmap(function(e){return r.concat([o],e)}):0===i.length?n.Sequence.from([[]]):n.Sequence.from(i).filterM(e)})}})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}),define("src/lib/monad/sequence/member/instance/map",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.map=function(e){var t=this;return new n.Sequence(function(r){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return n.Sequence.Data.cons()},function(t){return n.Sequence.Data.cons(e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.index(t)),n.Sequence.Thunk.iterator(t))})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/filter",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.filter=function(e){var t=this;return new n.Sequence(function(r,i){return void 0===r&&(r=function(){return t.iterate()}),n.Sequence.Iterator.when(r(),function(){return i()},function(t,r){return e(n.Sequence.Thunk.value(t),n.Sequence.Thunk.index(t))?i(n.Sequence.Thunk.value(t),n.Sequence.Thunk.iterator(t)):r()})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/monad/sequence/member/instance/scan",["require","exports","src/lib/monad/sequence/core"],function(e,t,n){"use strict";var r=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.scan=function(e,t){var r=this;return new n.Sequence(function(i){var o=void 0===i?[void 0,void 0]:i,u=o[0],c=void 0===u?t:u,s=o[1],a=void 0===s?function(){return r.iterate()}:s;return n.Sequence.Iterator.when(a(),function(){return n.Sequence.Data.cons()},function(t){return n.Sequence.Data.cons(c=e(c,n.Sequence.Thunk.value(t)),[c,n.Sequence.Thunk.iterator(t)])})})},t}(n.Sequence);Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r}),define("src/lib/assign",["require","exports","src/lib/type"],function(e,t,n){"use strict";function r(e){return function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(void 0===t||null===t)throw new TypeError("Spica: assign: Cannot walk on "+t+".");for(var i=0,o=n;i<o.length;i++){var u=o[i];if(void 0!==u&&null!==u)for(var c=0,s=Object.keys(Object(u));c<s.length;c++){var a=s[c],f=Object.getOwnPropertyDescriptor(Object(u),a);void 0!==f&&f.enumerable&&void e(a,Object(t),Object(u))}}return Object(t)}}t.assign=r(function(e,t,n){return t[e]=n[e]}),t.clone=r(function(e,r,i){switch(n.type(i[e])){case"Array":return r[e]=t.clone([],i[e]);case"Function":case"Object":return r[e]=t.clone({},i[e]);default:return r[e]=i[e]}}),t.extend=r(function(e,r,i){switch(n.type(i[e])){case"Array":return r[e]=t.extend([],i[e]);case"Function":case"Object":switch(n.type(r[e])){case"Function":case"Object":return r[e]=t.extend(r[e],i[e]);default:return r[e]=t.extend({},i[e])}default:return r[e]=i[e]}})}),define("src/lib/compose",["require","exports","src/lib/assign","src/lib/concat"],function(e,t,n,r){"use strict";function i(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];return r.concat([e],t).reduce(function(e,t){void n.assign(e.prototype,t.prototype);for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e})}t.compose=i}),define("src/lib/monad/sequence",["require","exports","src/lib/monad/sequence/core","src/lib/monad/sequence/member/static/from","src/lib/monad/sequence/member/static/write","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/union","src/lib/monad/sequence/member/static/intersect","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/instance/iterate","src/lib/monad/sequence/member/instance/memoize","src/lib/monad/sequence/member/instance/read","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/compose"],function(e,t,n,r,i,o,u,c,s,a,f,d,l,h,p,v,m,b,q,y,S,x,_,w,g,k,T,M,O,I,j){"use strict";t.Sequence=n.Sequence,j.compose(n.Sequence,r["default"],i["default"],o["default"],u["default"],c["default"],s["default"],a["default"],f["default"],d["default"],l["default"],h["default"],p["default"],v["default"],m["default"],b["default"],q["default"],y["default"],S["default"],x["default"],_["default"],w["default"],g["default"],k["default"],T["default"],M["default"],O["default"],I["default"])}),define("src/lib/collection/attrmap",["require","exports"],function(e,t){"use strict";var n=function(){function e(){this.store=new WeakMap}return e.prototype.get=function(e,t){return this.store.get(e)&&this.store.get(e).get(t)},e.prototype.set=function(e,t,n){var r=this.store.has(e)?this.store.get(e):this.store.set(e,new Map).get(e);return void r.set(t,n),this},e.prototype.has=function(e,t){return this.store.has(e)&&this.store.get(e).has(t)},e.prototype["delete"]=function(e,t){return void 0===t?this.store["delete"](e):this.store.has(e)?this.store.get(e)["delete"](t):!1},e}();t.AttrMap=n}),define("src/lib/collection/relationmap",["require","exports"],function(e,t){"use strict";var n=function(){function e(){this.store=new WeakMap}return e.prototype.get=function(e,t){return this.store.get(e)&&this.store.get(e).get(t)},e.prototype.set=function(e,t,n){var r=this.store.has(e)?this.store.get(e):this.store.set(e,new WeakMap).get(e);return void r.set(t,n),this},e.prototype.has=function(e,t){return this.store.has(e)&&this.store.get(e).has(t)},e.prototype["delete"]=function(e,t){return void 0===t?this.store["delete"](e):this.store.has(e)?this.store.get(e)["delete"](t):!1},e}();t.RelationMap=n}),define("src/lib/mixin",["require","exports","src/lib/assign"],function(e,t,n){"use strict";function r(){for(var e=[],t=0;t<arguments.length;t++)e[t-0]=arguments[t];return e.reduceRight(function(e,t){return i(t,e)},function(){function e(){}return e}())}function i(e,t){var r=function(){function n(){return e.apply(t.apply(this,arguments)||this,arguments)}return n}();void n.assign(r.prototype,e.prototype,t.prototype);for(var i in t)t.hasOwnProperty(i)&&(r[i]=t[i]);for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i]);return r}t.Mixin=r}),define("src/lib/fingerprint",["require","exports"],function(e,t){"use strict";function n(){return i(o([u(window.navigator),u(window.screen),u((new Date).getTimezoneOffset())].join()))}function r(){return i(o([u(process)].join()))}function i(e){return e.split("").reduce(function(e,t,n){return(+t*n+e)%1e9||e-+t},0)}function o(e){return e.split("").map(function(e){return e.charCodeAt(0)}).join("")}function u(e,t){if(void 0===t&&(t=5),t>0&&e&&"object"==typeof e){var n="{";for(var r in e)n+='"'+r+'": '+u(e[r],t-1)+",";return n+="}"}return!e||e.toString?'"'+e+'"':'"'+Object.prototype.toString.call(e)+'"'}t.FINGERPRINT="object"==typeof window?n():r(),t.browser=n,t.server=r,t.hash=i,t.str2digit=o,t.stringify=u}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(e,t,n){"use strict";function r(){var e=u=u*Date.now()%1e15;if(16>e||e>1e15)throw new Error("Spica: uuid: Invalid uuid dynamic seed.");for(var t="",n=0,r=o;n<r.length;n++){var i=r[n];if("x"===i||"y"===i){var c=Math.random()*e%16|0,s="x"==i?c:3&c|8;t+=s.toString(16)}else t+=i}return t.toLowerCase()}var i=n.FINGERPRINT*Date.now()%1e15;if(!i||"number"!=typeof i||100>i||i>1e15)throw new Error("Spica: uuid: Invalid uuid static seed.\n "+n.FINGERPRINT);var o=Object.freeze("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split("")),u=i;t.v4=r}),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/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"],function(e,t,n,r,i,o,u,c,s,a,f,d,l,h,p,v,m,b){"use strict";t.Supervisor=n.Supervisor,t.Observable=r.Observable,t.Cancelable=i.Cancelable,t.Sequence=o.Sequence,t.Maybe=u.Maybe,t.Just=u.Just,t.Nothing=u.Nothing,t.Either=c.Either,t.Left=c.Left,t.Right=c.Right,t.DataMap=s.DataMap,t.AttrMap=a.AttrMap,t.RelationMap=f.RelationMap,t.Mixin=d.Mixin,t.Tick=l.Tick,t.FINGERPRINT=h.FINGERPRINT,t.uuid=p.v4,t.sqid=v.sqid,t.assign=m.assign,t.clone=m.clone,t.extend=m.extend,t.concat=b.concat}),define("spica",["require","exports","src/export"],function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}r(n)}); |
@@ -35,4 +35,5 @@ module.exports = function (config) { | ||
autoWatch: true, | ||
browsers: ['Chrome'] | ||
browsers: ['Chrome'], | ||
browserNoActivityTimeout: 100 * 1e3 | ||
}); | ||
}; |
{ | ||
"name": "spica", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Supervisor, Observable, Sequence, Maybe, Either and some utils.", | ||
@@ -40,3 +40,3 @@ "private": false, | ||
"gulp-footer": "^1.0.5", | ||
"gulp-header": "^1.8.2", | ||
"gulp-header": "1.8.2", | ||
"gulp-load-plugins": "^1.2.4", | ||
@@ -43,0 +43,0 @@ "gulp-mocha": "^2.2.0", |
@@ -71,14 +71,15 @@ import {Return, Left, Right, Either} from './either'; | ||
it('Functor law 1', () => { | ||
const f = (n: number) => n, | ||
x = 0; | ||
const f = <T>(n: T) => n; | ||
const x = 0; | ||
const fa = Return(x).fmap(f); | ||
assert(fa.extract() === 0); | ||
const fb = f(Return(x)); | ||
assert(fa.extract() === fb.extract()); | ||
}); | ||
it('Functor law 2', () => { | ||
const f = (n: number) => n + 2, | ||
g = (n: number) => n * 3, | ||
x = 1; | ||
const fa = Return(x).fmap(n => g(f(n))), | ||
fb = Return(x).fmap(f).fmap(g); | ||
const f = (n: number) => n + 2; | ||
const g = (n: number) => n * 3; | ||
const x = 1; | ||
const fa = Return(x).fmap(n => g(f(n))); | ||
const fb = Return(x).fmap(f).fmap(g); | ||
assert(fa.extract() === fb.extract()); | ||
@@ -88,4 +89,4 @@ }); | ||
it('Monad law 1', () => { | ||
const f = (n: number) => Right(n + 1), | ||
x = 0; | ||
const f = (n: number) => Right(n + 1); | ||
const x = 0; | ||
const ma = Return(x).bind(f); | ||
@@ -97,4 +98,4 @@ const mb = f(x); | ||
it('Monad law 2', () => { | ||
const f = (n: number) => Right(n + 1), | ||
x = 0; | ||
const f = (n: number) => Right(n + 1); | ||
const x = 0; | ||
const ma = Return(x); | ||
@@ -106,15 +107,13 @@ const mb = ma.bind(Return); | ||
it('Monad law 3', () => { | ||
let ord1 = 0, | ||
ord2 = 0; | ||
const m1 = Return(1), | ||
m2 = Return(2), | ||
m3 = Return(4); | ||
const m1 = Return(1); | ||
const m2 = Return(2); | ||
const m3 = Return(4); | ||
const ma = m1 | ||
.bind(v1 => m2.bind(v2 => Right(+assert(++ord1 === 1) || v1 + v2))) | ||
.bind(n => m3.bind(v3 => Right(+assert(++ord1 === 2) || n + v3))); | ||
.bind(v1 => m2.bind(v2 => Right(v1 + v2))) | ||
.bind(n => m3.bind(v3 => Right(n + v3))); | ||
const mb = m1 | ||
.bind(v1 => m2.bind(v2 => m3.bind(v3 => | ||
Right(+assert(++ord2 === 1) || v2 + v3))) | ||
Right(v2 + v3))) | ||
.bind(n => | ||
Right(+assert(++ord2 === 2) || v1 + n))); | ||
Right(v1 + n))); | ||
assert(ma.extract() === mb.extract()); | ||
@@ -121,0 +120,0 @@ }); |
@@ -71,14 +71,15 @@ import {Return, Just, Nothing, Maybe} from './maybe'; | ||
it('Functor law 1', () => { | ||
const f = (n: number) => n, | ||
x = 0; | ||
const f = <T>(n: T) => n; | ||
const x = 0; | ||
const fa = Return(x).fmap(f); | ||
assert(fa.extract() === 0); | ||
const fb = f(Return(x)); | ||
assert(fa.extract() === fb.extract()); | ||
}); | ||
it('Functor law 2', () => { | ||
const f = (n: number) => n + 2, | ||
g = (n: number) => n * 3, | ||
x = 1; | ||
const fa = Return(x).fmap(n => g(f(n))), | ||
fb = Return(x).fmap(f).fmap(g); | ||
const f = (n: number) => n + 2; | ||
const g = (n: number) => n * 3; | ||
const x = 1; | ||
const fa = Return(x).fmap(n => g(f(n))); | ||
const fb = Return(x).fmap(f).fmap(g); | ||
assert(fa.extract() === fb.extract()); | ||
@@ -88,4 +89,4 @@ }); | ||
it('Monad law 1', () => { | ||
const f = (n: number) => Just(n + 1), | ||
x = 0; | ||
const f = (n: number) => Just(n + 1); | ||
const x = 0; | ||
const ma = Return(x).bind(f); | ||
@@ -97,4 +98,4 @@ const mb = f(x); | ||
it('Monad law 2', () => { | ||
const f = (n: number) => Just(n + 1), | ||
x = 0; | ||
const f = (n: number) => Just(n + 1); | ||
const x = 0; | ||
const ma = Return(x); | ||
@@ -106,15 +107,13 @@ const mb = ma.bind(Return); | ||
it('Monad law 3', () => { | ||
let ord1 = 0, | ||
ord2 = 0; | ||
const m1 = Return(1), | ||
m2 = Return(2), | ||
m3 = Return(4); | ||
const m1 = Return(1); | ||
const m2 = Return(2); | ||
const m3 = Return(4); | ||
const ma = m1 | ||
.bind(v1 => m2.bind(v2 => Just(+assert(++ord1 === 1) || v1 + v2))) | ||
.bind(n => m3.bind(v3 => Just(+assert(++ord1 === 2) || n + v3))); | ||
.bind(v1 => m2.bind(v2 => Just(v1 + v2))) | ||
.bind(n => m3.bind(v3 => Just(n + v3))); | ||
const mb = m1 | ||
.bind(v1 => m2.bind(v2 => m3.bind(v3 => | ||
Just(+assert(++ord2 === 1) || v2 + v3))) | ||
Just(v2 + v3))) | ||
.bind(n => | ||
Just(+assert(++ord2 === 2) || v1 + n))); | ||
Just(v1 + n))); | ||
assert(ma.extract() === mb.extract()); | ||
@@ -121,0 +120,0 @@ }); |
@@ -9,2 +9,6 @@ import {Sequence} from './sequence/core'; | ||
import intersect from './sequence/member/static/intersect'; | ||
import Return from './sequence/member/static/return'; | ||
import mempty from './sequence/member/static/mempty'; | ||
import mconcat from './sequence/member/static/mconcat'; | ||
import mappend from './sequence/member/static/mappend'; | ||
import iterate from './sequence/member/instance/iterate'; | ||
@@ -37,2 +41,6 @@ import memoize from './sequence/member/instance/memoize'; | ||
intersect, | ||
Return, | ||
mempty, | ||
mconcat, | ||
mappend, | ||
iterate, | ||
@@ -39,0 +47,0 @@ memoize, |
@@ -17,8 +17,12 @@ import {Monad} from '../monad'; | ||
export declare function random<T>(as: T[]): Sequence<T, Sequence.Iterator<number>>; | ||
export declare function concat<T>(ss: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
export declare function concat<T>(ss: Sequence<Sequence<T, any>, any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]>; | ||
export declare function concat<T>(ss: Sequence<T[], any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]>; | ||
export declare function concat<T>(as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
export declare function concat<T>(as: Sequence<Sequence<T, any>, any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]>; | ||
export declare function concat<T>(as: Sequence<T[], any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]>; | ||
export declare function zip<T, U>(a: Sequence<T, any>, b: Sequence<U, any>): Sequence<[T, U], [Sequence.Iterator<T>, Sequence.Iterator<U>]>; | ||
export declare function union<T>(cmp: (a: T, b: T) => number, ss: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
export declare function intersect<T>(cmp: (a: T, b: T) => number, ss: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
export declare function union<T>(cmp: (a: T, b: T) => number, as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
export declare function intersect<T>(cmp: (a: T, b: T) => number, as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
export declare function Return<T>(a: T): Sequence<T, number>; | ||
export declare const mempty: Sequence<any, any>; | ||
export declare function mappend<T>(a: Sequence<T, any>, b: Sequence<T, any>): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
export declare function mconcat<T>(as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
} | ||
@@ -25,0 +29,0 @@ export interface Sequence<T, S> { |
@@ -7,9 +7,9 @@ import {Sequence} from '../../core'; | ||
Sequence.Iterator.when( | ||
iter(), | ||
n > 0 ? iter() : <Sequence.Thunk<T>>Sequence.Iterator.done(), | ||
() => cons(), | ||
thunk => | ||
Sequence.Thunk.index(thunk) < n | ||
Sequence.Thunk.index(thunk) + 1 < n | ||
? cons(Sequence.Thunk.value(thunk), Sequence.Thunk.iterator(thunk)) | ||
: cons())); | ||
: cons(Sequence.Thunk.value(thunk)))); | ||
} | ||
} |
import {Sequence} from '../../core'; | ||
export default class <T, S> extends Sequence<T, S> { | ||
public static concat<T>(ss: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]> | ||
public static concat<T>(ss: Sequence<Sequence<T, any>, any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]> | ||
public static concat<T>(ss: Sequence<T[], any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]> | ||
public static concat<T>(ss: Sequence<T, any>[] | Sequence<Sequence<T, any>, any> | Sequence<T[], any>): Sequence<T, [Sequence.Iterator<T> | Sequence.Iterator<T[]>, Sequence.Iterator<T>]> { | ||
return Array.isArray(ss) | ||
? ss.reduce((a, b) => concat(a, b), Sequence.from([])) | ||
: (<Sequence<T[], any>>ss).bind((s: Sequence<T, any> | T[]) => | ||
public static concat<T>(as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]> | ||
public static concat<T>(as: Sequence<Sequence<T, any>, any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]> | ||
public static concat<T>(as: Sequence<T[], any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]> | ||
public static concat<T>(as: Sequence<T, any>[] | Sequence<Sequence<T, any>, any> | Sequence<T[], any>): Sequence<T, [Sequence.Iterator<T> | Sequence.Iterator<T[]>, Sequence.Iterator<T>]> { | ||
return Array.isArray(as) | ||
? Sequence.mconcat(as) | ||
: (<Sequence<T[], any>>as).bind((s: Sequence<T, any> | T[]) => | ||
Array.isArray(s) | ||
@@ -16,13 +16,1 @@ ? Sequence.from(s) | ||
} | ||
function concat<T>(a: Sequence<T, any>, b: Sequence<T, any>): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]> { | ||
return new Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>(([ai, bi] = [() => a.iterate(), () => b.iterate()], cons) => | ||
Sequence.Iterator.when( | ||
ai(), | ||
() => | ||
Sequence.Iterator.when( | ||
bi(), | ||
() => cons(), | ||
bt => cons(Sequence.Thunk.value(bt), [Sequence.Iterator.done, Sequence.Thunk.iterator(bt)])), | ||
at => cons(Sequence.Thunk.value(at), [Sequence.Thunk.iterator(at), bi]))); | ||
} |
@@ -8,3 +8,2 @@ import {Sequence} from '../../../sequence'; | ||
Sequence.from([]) | ||
.takeWhile(() => true) | ||
.read(), | ||
@@ -14,3 +13,2 @@ []); | ||
Sequence.from([0]) | ||
.takeWhile(() => true) | ||
.read(), | ||
@@ -20,3 +18,2 @@ [0]); | ||
Sequence.from([0, 1]) | ||
.takeWhile(() => true) | ||
.read(), | ||
@@ -26,3 +23,2 @@ [0, 1]); | ||
Sequence.from([0, 1, 2]) | ||
.takeWhile(() => true) | ||
.read(), | ||
@@ -29,0 +25,0 @@ [0, 1, 2]); |
import {Sequence} from '../../core'; | ||
export default class <T, S> extends Sequence<T, S> { | ||
public static intersect<T>(cmp: (a: T, b: T) => number, ss: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]> { | ||
return ss.reduce((a, b) => intersect(cmp, a, b)); | ||
public static intersect<T>(cmp: (a: T, b: T) => number, as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]> { | ||
return as.reduce((a, b) => intersect(cmp, a, b)); | ||
} | ||
@@ -7,0 +7,0 @@ } |
import {Sequence} from '../../core'; | ||
export default class <T, S> extends Sequence<T, S> { | ||
public static union<T>(cmp: (a: T, b: T) => number, ss: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]> { | ||
return ss.reduce((a, b) => union(cmp, a, b)); | ||
public static union<T>(cmp: (a: T, b: T) => number, as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]> { | ||
return as.reduce((a, b) => union(cmp, a, b)); | ||
} | ||
@@ -7,0 +7,0 @@ } |
@@ -10,3 +10,2 @@ import {Sequence} from '../../../sequence'; | ||
seq | ||
.takeWhile(() => true) | ||
.read(), | ||
@@ -16,3 +15,2 @@ [0, 1, 2]); | ||
seq | ||
.takeWhile(() => true) | ||
.read(), | ||
@@ -23,12 +21,31 @@ []); | ||
seq | ||
.drop(0) | ||
.take(1) | ||
.read(), | ||
[3]); | ||
stream.length = 0; | ||
assert.deepStrictEqual( | ||
seq | ||
.drop(0) | ||
.take(1) | ||
.read(), | ||
[4]); | ||
stream.push(5); | ||
assert.deepStrictEqual( | ||
seq | ||
.drop(0) | ||
.take(0) | ||
.read(), | ||
[]); | ||
assert.deepStrictEqual( | ||
seq | ||
.drop(0) | ||
.take(1) | ||
.read(), | ||
[5]); | ||
stream.push(6); | ||
stream.length = 0; | ||
assert.deepStrictEqual( | ||
seq | ||
.read(), | ||
[]); | ||
}); | ||
@@ -35,0 +52,0 @@ |
@@ -91,7 +91,10 @@ /** | ||
static zip<T, U>(a: Sequence<T, any>, b: Sequence<U, any>): Sequence<[T, U], [Sequence.Iterator<T>, Sequence.Iterator<U>]>; | ||
static concat<T>(ss: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
static concat<T>(ss: Sequence<Sequence<T, any>, any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]>; | ||
static concat<T>(ss: Sequence<T[], any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]>; | ||
static union<T>(cmp: (a: T, b: T) => number, ss: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
static intersect<T>(cmp: (a: T, b: T) => number, ss: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
static concat<T>(as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
static concat<T>(as: Sequence<Sequence<T, any>, any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]>; | ||
static concat<T>(as: Sequence<T[], any>): Sequence<T, [Sequence.Iterator<T[]>, Sequence.Iterator<T>]>; | ||
static union<T>(cmp: (a: T, b: T) => number, as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
static intersect<T>(cmp: (a: T, b: T) => number, as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
static mempty: Sequence<any, any>; | ||
static mappend<T>(a: Sequence<T, any>, b: Sequence<T, any>): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
static mconcat<T>(as: Sequence<T, any>[]): Sequence<T, [Sequence.Iterator<T>, Sequence.Iterator<T>]>; | ||
constructor(cons: (p: S, cons: (value?: T, next?: S) => Sequence.Data<T, S>) => Sequence.Data<T, S>); | ||
@@ -98,0 +101,0 @@ iterate(): Sequence.Thunk<T>; |
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
310466
114
8150