monad-ts
Version:
Monad-ts is a small library implements some of key monads and way to chain them in a pipe (flow) in JavaScript and TypeScript. Angular 2+ compatible.
1 lines • 11 kB
JavaScript
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.Monad_ts=r():t.Monad_ts=r()}(this,function(){return function(t){function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}var e={};return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=5)}([function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function t(){}return t.prototype.fail=function(t){return t instanceof Error?t:new Error(t)},t.prototype.just=function(t,r){return t(r)},t}();r.Monad=n},function(t,r,e){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};return function(r,e){function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=e(0),i=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return n(r,t),r.prototype.bind=function(t,r){if(r!==r||r===1/0||r===-1/0||r instanceof Error)return this.fail(r);var e=this.just(t,r);return e!==e||e===1/0||e===-1/0||e instanceof Error?this.fail(e):e},r}(o.Monad);r.ErrorM=i},function(t,r,e){"use strict";function n(t,r){if(void 0===r&&(r=new Map),Object(t)!==t)return t;if(r.has(t))return r.get(t);var e=Array.isArray(t)?[]:t.constructor&&t.constructor()?t.constructor():Object.create(t);return Object(e)!==e?(r.set(t,t),e=t):r.set(t,e),t instanceof Map?Array.from(t,function(t){var n=t[0],i=t[1];return e.set(n,o(i,r))})[0]:Object.assign.apply(Object,[e].concat(Object.keys(t).map(function(e){return n={},n[e]=o(t[e],r),n;var n})))}function o(t,r){return n(t,r)}Object.defineProperty(r,"__esModule",{value:!0}),r.clone=n},function(t,r,e){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};return function(r,e){function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=e(0),i=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return n(r,t),r.prototype.bind=function(t,r){if(null===r||void 0===r)return this.nothing();var e=this.just(t,r);return null===e||void 0===e?this.nothing():e},r.prototype.nothing=function(){return null},r}(o.Monad);r.Maybe=i},function(t,r,e){"use strict";function n(t,r){var e=new Object(t),i=new Object(r);if(e!==t&&i!==r)return Object.is(t,r);if(e!==t||i!==r)return!1;var u=t.constructor,c=r.constructor;if(u!==c)return!1;if(u===Array&&c===Array)return t.length===r.length&&o(t,r);if(u===Function&&c===Function)return t.toString()===r.toString();if(n(Object.getOwnPropertyNames(t),Object.getOwnPropertyNames(r))){for(var a in t)if(t.hasOwnProperty(a)&&!n(t[a],r[a]))return!1;return!0}}function o(t,r){return!t.some(function(t,e){return Array.isArray(t)?o(t,r[e]):"object"==typeof t||"function"==typeof t?!n(t,r[e]):!Object.is(t,r[e])})}Object.defineProperty(r,"__esModule",{value:!0}),r.equality=n},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var n=e(6);r.AsyncFlow=n.AsyncFlow;var o=e(7);r.cast=o.cast;var i=e(2);r.clone=i.clone;var u=e(8);r.debounceTime=u.debounceTime;var c=e(9);r.Either=c.Either;var a=e(1);r.ErrorM=a.ErrorM;var s=e(4);r.equality=s.equality;var f=e(10);r.Flow=f.Flow;var p=e(11);r.hash=p.hash;var l=e(12);r.Identity=l.Identity;var y=e(13);r.List=y.List;var h=e(3);r.Maybe=h.Maybe;var d=e(0);r.Monad=d.Monad;var _=e(14);r.State=_.State;var v=e(15);r.wait=v.wait},function(t,r,e){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};return function(r,e){function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=e(3),i=e(1),u=e(2),c=e(0),a=function(t){function r(r,e){void 0===r&&(r=0),void 0===e&&(e=!0);var n=t.call(this)||this;return n.flow=e?u.clone(r):r,n.maybe=new o.Maybe,n.err=new i.ErrorM,n}return n(r,t),r.prototype.bind=function(t){var r=this;return new Promise(function(e){e(r.err.bind(function(e){return r.maybe.bind(function(r){return t(r)},e)},r.flow))})},r}(c.Monad);r.AsyncFlow=a},function(t,r,e){"use strict";function n(t,r){return void 0===r&&(r=0),"number"==typeof r&&Array.isArray(t)?r>0?o(t,r):t:new Error("Function cast. Input must be array and factor - number.")}function o(t,r){return t.length?t.reduce(function(t,e){return t.concat(i(e,r))},[]):t}function i(t,r){return 1===r?t:o(t,r-1)}Object.defineProperty(r,"__esModule",{value:!0}),r.cast=n},function(t,r,e){"use strict";function n(t,r,e){var n=this;void 0===e&&(e=!0);var o;return function(){for(var i=[],u=0;u<arguments.length;u++)i[u]=arguments[u];var c=function(){o=null,e||t.apply(n,i)},a=e&&!o;clearTimeout(o),o=setTimeout(c,r),a&&t.apply(n,i)}}Object.defineProperty(r,"__esModule",{value:!0}),r.debounceTime=n},function(t,r,e){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};return function(r,e){function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=e(0),i=e(4),u=function(t){function r(r,e){var n=t.call(this)||this;return n.r=r,n.l=e,n}return n(r,t),r.prototype.bind=function(t,r){this.uVal=r;try{switch(t(r)){case!0:return this.r(r);case!1:return this.l(r);default:return this.fail("Either.bind() - binding error")}}catch(t){this.fail("Either.bind().switch - "+t)}},r.prototype.left=function(t){return this.uVal?i.equality(this.uVal,t)?this.l(t):this.fail("Either.left() - v have been binded with bind method"):this.l(t)},r.prototype.right=function(t){return this.uVal?i.equality(this.uVal,t)?this.r(t):this.fail("Either.right() - v have been binded with bind method"):this.r(t)},r}(o.Monad);r.Either=u},function(t,r,e){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};return function(r,e){function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=e(0),i=e(3),u=e(2),c=e(1),a=function(t){function r(r,e){void 0===e&&(e=!0);var n=t.call(this)||this;return n.flow=e?u.clone(r):r,n.maybe=new i.Maybe,n.err=new c.ErrorM,n}return n(r,t),r.prototype.bind=function(t,r){var e=this;return void 0===r&&(r=this.flow),this.flow=this.err.bind(function(r){return e.maybe.bind(function(r){return t(r)},r)},r),this},r.prototype.let=function(t){return t(u.clone(this.flow)),this},r.prototype.subscribe=function(){return this.flow},r}(o.Monad);r.Flow=a},function(t,r,e){"use strict";function n(t,r){if(void 0===r&&(r=2166136261),0===t.length||!t)return null;for(var e=t.length-1,n=r;e>=0;)n^=t.charCodeAt(e--),n+=(n<<1)+(n<<4)+(n<<7)+(n<<8)+(n<<24);return n}Object.defineProperty(r,"__esModule",{value:!0}),r.hash=n},function(t,r,e){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};return function(r,e){function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=e(0),i=e(2),u=e(4),c=e(1),a=function(t){function r(r){var e=t.call(this)||this;return e.v=i.clone(r),e.err=new c.ErrorM,e}return n(r,t),r.prototype.bind=function(t,r){return void 0===r&&(r=this.v),this.v&&r?u.equality(this.v,r)?t(r):this.fail("Identity.bind() - underlying value of the monad have defined in the constructor!"):r||0===r||""===r||null===r?t(r):t()},r}(o.Monad);r.Identity=a},function(t,r,e){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};return function(r,e){function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=e(0),i=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return n(r,t),r.prototype.bind=function(t,r){return Array.isArray(r)?this._disp(t,r):this.fail("List.bind() - input must be an array.")},r.prototype._disp=function(t,r){var e=this;return r.map(function(r){return Array.isArray(r)?e._disp(t,r):t(r)})},r}(o.Monad);r.List=i},function(t,r,e){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])};return function(r,e){function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}();Object.defineProperty(r,"__esModule",{value:!0});var o=e(3),i=e(1),u=e(2),c=e(4),a=e(0),s=function(t){function r(r){var e=t.call(this)||this;return e.state=u.clone(r),e.maybe=new o.Maybe,e.err=new i.ErrorM,e}return n(r,t),r.prototype.bind=function(t,r){var e=!!this.state,n=!!r;switch(!0){case e&&n:this.state=this.fail("State.bind() - underlying value of the monad have defined in the constructor!");break;case!e&&!n:this.state=this.fail("State.bind() - underlying value of the monad have not defined!");break;case!e&&n:this.state=r}},r.prototype.put=function(t){var r=this,e=u.clone(this.state);this.state=this.err.bind(function(t){return c.equality(Object.getOwnPropertyNames(e),Object.getOwnPropertyNames(t))?t:r.fail("State.put()._maybeErrorT() - after init we can not add / remove keys in state obj.")},this.maybe.bind(function(r){return t(r)},this.state))},r.prototype.get=function(){return this.state},r}(a.Monad);r.State=s},function(t,r,e){"use strict";function n(t,r){return void 0===r&&(r=0),"number"==typeof r&&r>=0?new Promise(function(e){setTimeout(function(){return e(t)},r)}):Promise.reject(new Error("Function wait - timeout must be number >= 0."))}Object.defineProperty(r,"__esModule",{value:!0}),r.wait=n}])});