@swan-io/boxed
Advanced tools
Comparing version 0.2.0 to 0.2.1
import { Option } from "./Option"; | ||
export declare const from: { | ||
<T>(arrayLike: ArrayLike<T>): T[]; | ||
<T_1, U>(arrayLike: ArrayLike<T_1>, mapfn: (v: T_1, k: number) => U, thisArg?: any): U[]; | ||
<T_2>(iterable: Iterable<T_2> | ArrayLike<T_2>): T_2[]; | ||
<T_3, U_1>(iterable: Iterable<T_3> | ArrayLike<T_3>, mapfn: (v: T_3, k: number) => U_1, thisArg?: any): U_1[]; | ||
}; | ||
export declare const of: <T>(...items: T[]) => T[]; | ||
export declare const isArray: (arg: any) => arg is any[]; | ||
export declare const keepMap: <A, B>(array: A[], func: (item: A) => NonNullable<B> | null | undefined) => NonNullable<B>[]; | ||
@@ -3,0 +11,0 @@ export declare const getBy: <A>(array: A[], func: (item: A) => boolean) => Option<A>; |
@@ -1,2 +0,2 @@ | ||
var t=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag="None",this.value=void 0}var n=t.prototype;return n.map=function(t){return"Some"===this.tag?o.Some(t(this.value)):this},n.flatMap=function(t){return"Some"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Some"===this.tag?this.value:t},n.match=function(t){return"Some"===this.tag?t.Some(this.value):t.None()},n.toUndefined=function(){return"None"===this.tag?void 0:this.value},n.toNull=function(){return"None"===this.tag?null:this.value},n.isSome=function(){return"Some"===this.tag},n.isNone=function(){return"None"===this.tag},t}();t.prototype.__boxed_type__="Option";var n,e=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),r=((n=Object.create(e)).tag="None",n.value=void 0,n),o={Some:function(t){var n=Object.create(e);return n.tag="Some",n.value=t,n},None:function(){return r},fromNullable:function(t){return null==t?o.None():o.Some(t)},fromNull:function(t){return null===t?o.None():o.Some(t)},fromUndefined:function(t){return void 0===t?o.None():o.Some(t)},equals:function(t,n,e){return"Some"===t.tag&&"Some"===n.tag?e(t.value,n.value):t.tag===n.tag},pattern:{Some:function(t){return{tag:"Some",value:t}},None:{tag:"None"}}},u=function(t,n){return t===n?0:t>n?1:-1},i={__proto__:null,keepMap:function(t,n){var e=[];return t.forEach(function(t){var r=n(t);null!=r&&e.push(r)}),e},getBy:function(t,n){for(var e=-1;++e<t.length;){var r=t[e];if(n(r))return o.Some(r)}return o.None()},getIndexBy:function(t,n){for(var e=-1;++e<t.length;)if(n(t[e]))return o.Some(e);return o.None()},binarySearchBy:function(t,n,e){if(void 0===e&&(e=u),0===t.length)return-1;for(var r=0,o=t.length-1;;){var i=r+(o-r)/2|0;if(i===r||i===o)return o;var a=e(n,t[i]);if(0===a)return i;a>0?r=i:a<0&&(o=i)}}},a=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag="NotAsked",this.value=void 0}var n=t.prototype;return n.map=function(t){return"Done"===this.tag?v.Done(t(this.value)):this},n.flatMap=function(t){return"Done"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Done"===this.tag?this.value:t},n.match=function(t){return"Done"===this.tag?t.Done(this.value):"Loading"===this.tag?t.Loading():t.NotAsked()},n.isDone=function(){return"Done"===this.tag},n.isLoading=function(){return"Loading"===this.tag},n.isNotAsked=function(){return"NotAsked"===this.tag},n.toOption=function(){return"Done"===this.tag?o.Some(this.value):o.None()},t}();a.prototype.__boxed_type__="AsyncData";var c,l=Object.create(null,Object.getOwnPropertyDescriptors(a.prototype)),s=((c=Object.create(l)).tag="Loading",c.value=void 0,c),f=function(){var t=Object.create(l);return t.tag="NotAsked",t.value=void 0,t}(),v={Done:function(t){var n=Object.create(l);return n.tag="Done",n.value=t,n},Loading:function(){return s},NotAsked:function(){return f},equals:function(t,n,e){return"Done"===t.tag&&"Done"===n.tag?e(t.value,n.value):t.tag===n.tag},pattern:{Done:function(t){return{tag:"Done",value:t}},NotAsked:{tag:"NotAsked"},Loading:{tag:"Loading"}}},h=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag=void 0,this.value=void 0}var n=t.prototype;return n.map=function(t){return"Ok"===this.tag?d.Ok(t(this.value)):this},n.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Ok"===this.tag?this.value:t},n.match=function(t){return"Ok"===this.tag?t.Ok(this.value):t.Error(this.value)},n.isOk=function(){return"Ok"===this.tag},n.isError=function(){return"Error"===this.tag},n.toOption=function(){return"Ok"===this.tag?o.Some(this.value):o.None()},t}();h.prototype.__boxed_type__="Result";var g=Object.create(null,Object.getOwnPropertyDescriptors(h.prototype)),d={Ok:function(t){var n=Object.create(g);return n.tag="Ok",n.value=t,n},Error:function(t){var n=Object.create(g);return n.tag="Error",n.value=t,n},fromExecution:function(t){try{return d.Ok(t())}catch(t){return d.Error(t)}},fromPromise:function(t){try{return Promise.resolve(function(n,e){try{var r=Promise.resolve(t).then(function(t){return d.Ok(t)})}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}(0,function(t){return d.Error(t)}))}catch(t){return Promise.reject(t)}},equals:function(t,n,e){return t.tag===n.tag&&("Error"===t.tag&&"Error"===n.tag||e(t.value,n.value))},pattern:{Ok:function(t){return{tag:"Ok",value:t}},Error:function(t){return{tag:"Error",value:t}}}};function p(t){var n=this,e={};this.tag="Pending",this.pending=e,e.cancel=t(function(t){if("Pending"===n.tag){var e=n.pending.resolveCallbacks;null==e||e.forEach(function(n){return n(t)}),n.tag="Resolved",n.value=t,n.pending=void 0}})}var _=Object.create(null,Object.getOwnPropertyDescriptors(/*#__PURE__*/function(){function t(t){this.tag=void 0,this.value=void 0,this.pending=void 0,this.tag="Pending",this.pending={}}var n=t.prototype;return n.isPending=function(){return"Pending"===this.tag},n.isCancelled=function(){return"Cancelled"===this.tag},n.isResolved=function(){return"Resolved"===this.tag},n.get=function(t){if(this.isPending()){var n,e=this.pending;e.resolveCallbacks=null!=(n=e.resolveCallbacks)?n:[],e.resolveCallbacks.push(t)}this.isResolved()&&t(this.value)},n.onCancel=function(t){if(this.isPending()){var n,e=this.pending;e.cancelCallbacks=null!=(n=e.cancelCallbacks)?n:[],e.cancelCallbacks.push(t)}this.isCancelled()&&t()},n.cancel=function(){if("Pending"===this.tag){this.tag="Cancelled",this.value=void 0;var t=this.pending,n=t.cancelCallbacks;null==t.cancel||t.cancel(),null==n||n.forEach(function(t){return t()}),this.pending=void 0}},n.map=function(t,n){var e=this;void 0===n&&(n=!1);var r=m.make(function(r){if(e.get(function(n){r(t(n))}),n)return function(){e.cancel()}});return this.onCancel(function(){r.cancel()}),r},n.then=function(t){return this.get(t),this},n.flatMap=function(t,n){var e=this;void 0===n&&(n=!1);var r=m.make(function(o){if(e.get(function(n){var e=t(n);e.get(o),e.onCancel(function(){return r.cancel()})}),n)return function(){e.cancel()}});return this.onCancel(function(){r.cancel()}),r},n.tap=function(t){return this.get(t),this},n.tapOk=function(t){return this.get(function(n){n.match({Ok:function(n){return t(n)},Error:function(){}})}),this},n.tapError=function(t){return this.get(function(n){n.match({Ok:function(){},Error:function(n){return t(n)}})}),this},n.mapResult=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return n}})},n)},n.mapOk=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(n){return d.Ok(t(n))},Error:function(){return n}})},n)},n.mapError=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(){return n},Error:function(n){return d.Error(t(n))}})},n)},n.flatMapOk=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return m.value(n)}})},n)},n.flatMapError=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(){return m.value(n)},Error:function(n){return t(n)}})},n)},n.toPromise=function(){var t=this;return new Promise(function(n){t.get(n)})},n.resultToPromise=function(){var t=this;return new Promise(function(n,e){t.get(function(t){t.match({Ok:n,Error:e})})})},t}().prototype)),m={make:function(t){var n=Object.create(_);return p.call(n,t),n},value:function(t){var n=Object.create(_);return p.call(n,function(n){return n(t)}),n},fromPromise:function(t){return m.make(function(n){t.then(function(t){return n(d.Ok(t))},function(t){return n(d.Error(t))})})},all:function(t,n){void 0===n&&(n=!1);for(var e=t.length,r=m.value([]),o=0,u=function(){if(o>=e)return{v:r};var u=r;r=t[o].flatMap(function(t){return u.map(function(n){return n.push(t),n},n)},n),o++};;){var i=u();if("object"==typeof i)return i.v}}},O={make:function(){var t=void 0;return[m.make(function(n){t=n}),t]}},k={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},y=Symbol.for("NOT_COMPUTED"),b={__proto__:null,Lazy:function(t){var n={contents:y};return{get value(){return n.contents===y&&(n.contents=t()),n.contents}}}},N={__proto__:null,encode:function(t,n){return JSON.stringify(t,function(t,n){if(null!=n)return"Option"===n.__boxed_type__?{__boxed_type__:"Option",tag:n.tag,value:n.value}:"Result"===n.__boxed_type__?{__boxed_type__:"Result",tag:n.tag,value:n.value}:"AsyncData"===n.__boxed_type__?{__boxed_type__:"AsyncData",tag:n.tag,value:n.value}:n},n)},decode:function(t){return JSON.parse(t,function(t,n){return null==n?n:"Option"===n.__boxed_type__?"Some"===n.tag?o.Some(n.value):o.None():"Result"===n.__boxed_type__?"Ok"===n.tag?d.Ok(n.value):d.Error(n.value):"AsyncData"===n.__boxed_type__?"NotAsked"===n.tag?v.NotAsked():"Loading"===n.tag?v.Loading():v.Done(n.value):n})}};export{i as Array,v as AsyncData,O as Deferred,k as Dict,m as Future,b as Lazy,o as Option,d as Result,N as Serializer}; | ||
var t=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag="None",this.value=void 0}var n=t.prototype;return n.map=function(t){return"Some"===this.tag?o.Some(t(this.value)):this},n.flatMap=function(t){return"Some"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Some"===this.tag?this.value:t},n.match=function(t){return"Some"===this.tag?t.Some(this.value):t.None()},n.toUndefined=function(){return"None"===this.tag?void 0:this.value},n.toNull=function(){return"None"===this.tag?null:this.value},n.isSome=function(){return"Some"===this.tag},n.isNone=function(){return"None"===this.tag},t}();t.prototype.__boxed_type__="Option";var n,e=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),r=((n=Object.create(e)).tag="None",n.value=void 0,n),o={Some:function(t){var n=Object.create(e);return n.tag="Some",n.value=t,n},None:function(){return r},fromNullable:function(t){return null==t?o.None():o.Some(t)},fromNull:function(t){return null===t?o.None():o.Some(t)},fromUndefined:function(t){return void 0===t?o.None():o.Some(t)},equals:function(t,n,e){return"Some"===t.tag&&"Some"===n.tag?e(t.value,n.value):t.tag===n.tag},pattern:{Some:function(t){return{tag:"Some",value:t}},None:{tag:"None"}}},i=function(t,n){return t===n?0:t>n?1:-1},u={__proto__:null,from:Array.from,of:Array.of,isArray:Array.isArray,keepMap:function(t,n){var e=[];return t.forEach(function(t){var r=n(t);null!=r&&e.push(r)}),e},getBy:function(t,n){for(var e=-1;++e<t.length;){var r=t[e];if(n(r))return o.Some(r)}return o.None()},getIndexBy:function(t,n){for(var e=-1;++e<t.length;)if(n(t[e]))return o.Some(e);return o.None()},binarySearchBy:function(t,n,e){if(void 0===e&&(e=i),0===t.length)return-1;for(var r=0,o=t.length-1;;){var u=r+(o-r)/2|0;if(u===r||u===o)return o;var a=e(n,t[u]);if(0===a)return u;a>0?r=u:a<0&&(o=u)}}},a=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag="NotAsked",this.value=void 0}var n=t.prototype;return n.map=function(t){return"Done"===this.tag?v.Done(t(this.value)):this},n.flatMap=function(t){return"Done"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Done"===this.tag?this.value:t},n.match=function(t){return"Done"===this.tag?t.Done(this.value):"Loading"===this.tag?t.Loading():t.NotAsked()},n.isDone=function(){return"Done"===this.tag},n.isLoading=function(){return"Loading"===this.tag},n.isNotAsked=function(){return"NotAsked"===this.tag},n.toOption=function(){return"Done"===this.tag?o.Some(this.value):o.None()},t}();a.prototype.__boxed_type__="AsyncData";var c,s=Object.create(null,Object.getOwnPropertyDescriptors(a.prototype)),l=((c=Object.create(s)).tag="Loading",c.value=void 0,c),f=function(){var t=Object.create(s);return t.tag="NotAsked",t.value=void 0,t}(),v={Done:function(t){var n=Object.create(s);return n.tag="Done",n.value=t,n},Loading:function(){return l},NotAsked:function(){return f},equals:function(t,n,e){return"Done"===t.tag&&"Done"===n.tag?e(t.value,n.value):t.tag===n.tag},pattern:{Done:function(t){return{tag:"Done",value:t}},NotAsked:{tag:"NotAsked"},Loading:{tag:"Loading"}}},h=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag=void 0,this.value=void 0}var n=t.prototype;return n.map=function(t){return"Ok"===this.tag?d.Ok(t(this.value)):this},n.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Ok"===this.tag?this.value:t},n.match=function(t){return"Ok"===this.tag?t.Ok(this.value):t.Error(this.value)},n.isOk=function(){return"Ok"===this.tag},n.isError=function(){return"Error"===this.tag},n.toOption=function(){return"Ok"===this.tag?o.Some(this.value):o.None()},t}();h.prototype.__boxed_type__="Result";var g=Object.create(null,Object.getOwnPropertyDescriptors(h.prototype)),d={Ok:function(t){var n=Object.create(g);return n.tag="Ok",n.value=t,n},Error:function(t){var n=Object.create(g);return n.tag="Error",n.value=t,n},fromExecution:function(t){try{return d.Ok(t())}catch(t){return d.Error(t)}},fromPromise:function(t){try{return Promise.resolve(function(n,e){try{var r=Promise.resolve(t).then(function(t){return d.Ok(t)})}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}(0,function(t){return d.Error(t)}))}catch(t){return Promise.reject(t)}},equals:function(t,n,e){return t.tag===n.tag&&("Error"===t.tag&&"Error"===n.tag||e(t.value,n.value))},pattern:{Ok:function(t){return{tag:"Ok",value:t}},Error:function(t){return{tag:"Error",value:t}}}};function p(t){var n=this,e={};this.tag="Pending",this.pending=e,e.cancel=t(function(t){if("Pending"===n.tag){var e=n.pending.resolveCallbacks;null==e||e.forEach(function(n){return n(t)}),n.tag="Resolved",n.value=t,n.pending=void 0}})}var _=Object.create(null,Object.getOwnPropertyDescriptors(/*#__PURE__*/function(){function t(t){this.tag=void 0,this.value=void 0,this.pending=void 0,this.tag="Pending",this.pending={}}var n=t.prototype;return n.isPending=function(){return"Pending"===this.tag},n.isCancelled=function(){return"Cancelled"===this.tag},n.isResolved=function(){return"Resolved"===this.tag},n.get=function(t){if(this.isPending()){var n,e=this.pending;e.resolveCallbacks=null!=(n=e.resolveCallbacks)?n:[],e.resolveCallbacks.push(t)}this.isResolved()&&t(this.value)},n.onCancel=function(t){if(this.isPending()){var n,e=this.pending;e.cancelCallbacks=null!=(n=e.cancelCallbacks)?n:[],e.cancelCallbacks.push(t)}this.isCancelled()&&t()},n.cancel=function(){if("Pending"===this.tag){this.tag="Cancelled",this.value=void 0;var t=this.pending,n=t.cancelCallbacks;null==t.cancel||t.cancel(),null==n||n.forEach(function(t){return t()}),this.pending=void 0}},n.map=function(t,n){var e=this;void 0===n&&(n=!1);var r=m.make(function(r){if(e.get(function(n){r(t(n))}),n)return function(){e.cancel()}});return this.onCancel(function(){r.cancel()}),r},n.then=function(t){return this.get(t),this},n.flatMap=function(t,n){var e=this;void 0===n&&(n=!1);var r=m.make(function(o){if(e.get(function(n){var e=t(n);e.get(o),e.onCancel(function(){return r.cancel()})}),n)return function(){e.cancel()}});return this.onCancel(function(){r.cancel()}),r},n.tap=function(t){return this.get(t),this},n.tapOk=function(t){return this.get(function(n){n.match({Ok:function(n){return t(n)},Error:function(){}})}),this},n.tapError=function(t){return this.get(function(n){n.match({Ok:function(){},Error:function(n){return t(n)}})}),this},n.mapResult=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return n}})},n)},n.mapOk=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(n){return d.Ok(t(n))},Error:function(){return n}})},n)},n.mapError=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(){return n},Error:function(n){return d.Error(t(n))}})},n)},n.flatMapOk=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return m.value(n)}})},n)},n.flatMapError=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(){return m.value(n)},Error:function(n){return t(n)}})},n)},n.toPromise=function(){var t=this;return new Promise(function(n){t.get(n)})},n.resultToPromise=function(){var t=this;return new Promise(function(n,e){t.get(function(t){t.match({Ok:n,Error:e})})})},t}().prototype)),m={make:function(t){var n=Object.create(_);return p.call(n,t),n},value:function(t){var n=Object.create(_);return p.call(n,function(n){return n(t)}),n},fromPromise:function(t){return m.make(function(n){t.then(function(t){return n(d.Ok(t))},function(t){return n(d.Error(t))})})},all:function(t,n){void 0===n&&(n=!1);for(var e=t.length,r=m.value([]),o=0,i=function(){if(o>=e)return{v:r};var i=r;r=t[o].flatMap(function(t){return i.map(function(n){return n.push(t),n},n)},n),o++};;){var u=i();if("object"==typeof u)return u.v}}},O={make:function(){var t=void 0;return[m.make(function(n){t=n}),t]}},k={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},y=Symbol.for("NOT_COMPUTED"),b={__proto__:null,Lazy:function(t){var n={contents:y};return{get value(){return n.contents===y&&(n.contents=t()),n.contents}}}},N={__proto__:null,encode:function(t,n){return JSON.stringify(t,function(t,n){if(null!=n)return"Option"===n.__boxed_type__?{__boxed_type__:"Option",tag:n.tag,value:n.value}:"Result"===n.__boxed_type__?{__boxed_type__:"Result",tag:n.tag,value:n.value}:"AsyncData"===n.__boxed_type__?{__boxed_type__:"AsyncData",tag:n.tag,value:n.value}:n},n)},decode:function(t){return JSON.parse(t,function(t,n){return null==n?n:"Option"===n.__boxed_type__?"Some"===n.tag?o.Some(n.value):o.None():"Result"===n.__boxed_type__?"Ok"===n.tag?d.Ok(n.value):d.Error(n.value):"AsyncData"===n.__boxed_type__?"NotAsked"===n.tag?v.NotAsked():"Loading"===n.tag?v.Loading():v.Done(n.value):n})}};export{u as Array,v as AsyncData,O as Deferred,k as Dict,m as Future,b as Lazy,o as Option,d as Result,N as Serializer}; | ||
//# sourceMappingURL=Boxed.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var t=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag="None",this.value=void 0}var n=t.prototype;return n.map=function(t){return"Some"===this.tag?o.Some(t(this.value)):this},n.flatMap=function(t){return"Some"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Some"===this.tag?this.value:t},n.match=function(t){return"Some"===this.tag?t.Some(this.value):t.None()},n.toUndefined=function(){return"None"===this.tag?void 0:this.value},n.toNull=function(){return"None"===this.tag?null:this.value},n.isSome=function(){return"Some"===this.tag},n.isNone=function(){return"None"===this.tag},t}();t.prototype.__boxed_type__="Option";var n,e=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),r=((n=Object.create(e)).tag="None",n.value=void 0,n),o={Some:function(t){var n=Object.create(e);return n.tag="Some",n.value=t,n},None:function(){return r},fromNullable:function(t){return null==t?o.None():o.Some(t)},fromNull:function(t){return null===t?o.None():o.Some(t)},fromUndefined:function(t){return void 0===t?o.None():o.Some(t)},equals:function(t,n,e){return"Some"===t.tag&&"Some"===n.tag?e(t.value,n.value):t.tag===n.tag},pattern:{Some:function(t){return{tag:"Some",value:t}},None:{tag:"None"}}},u=function(t,n){return t===n?0:t>n?1:-1},i={__proto__:null,keepMap:function(t,n){var e=[];return t.forEach(function(t){var r=n(t);null!=r&&e.push(r)}),e},getBy:function(t,n){for(var e=-1;++e<t.length;){var r=t[e];if(n(r))return o.Some(r)}return o.None()},getIndexBy:function(t,n){for(var e=-1;++e<t.length;)if(n(t[e]))return o.Some(e);return o.None()},binarySearchBy:function(t,n,e){if(void 0===e&&(e=u),0===t.length)return-1;for(var r=0,o=t.length-1;;){var i=r+(o-r)/2|0;if(i===r||i===o)return o;var a=e(n,t[i]);if(0===a)return i;a>0?r=i:a<0&&(o=i)}}},a=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag="NotAsked",this.value=void 0}var n=t.prototype;return n.map=function(t){return"Done"===this.tag?v.Done(t(this.value)):this},n.flatMap=function(t){return"Done"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Done"===this.tag?this.value:t},n.match=function(t){return"Done"===this.tag?t.Done(this.value):"Loading"===this.tag?t.Loading():t.NotAsked()},n.isDone=function(){return"Done"===this.tag},n.isLoading=function(){return"Loading"===this.tag},n.isNotAsked=function(){return"NotAsked"===this.tag},n.toOption=function(){return"Done"===this.tag?o.Some(this.value):o.None()},t}();a.prototype.__boxed_type__="AsyncData";var c,s=Object.create(null,Object.getOwnPropertyDescriptors(a.prototype)),l=((c=Object.create(s)).tag="Loading",c.value=void 0,c),f=function(){var t=Object.create(s);return t.tag="NotAsked",t.value=void 0,t}(),v={Done:function(t){var n=Object.create(s);return n.tag="Done",n.value=t,n},Loading:function(){return l},NotAsked:function(){return f},equals:function(t,n,e){return"Done"===t.tag&&"Done"===n.tag?e(t.value,n.value):t.tag===n.tag},pattern:{Done:function(t){return{tag:"Done",value:t}},NotAsked:{tag:"NotAsked"},Loading:{tag:"Loading"}}},h=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag=void 0,this.value=void 0}var n=t.prototype;return n.map=function(t){return"Ok"===this.tag?p.Ok(t(this.value)):this},n.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Ok"===this.tag?this.value:t},n.match=function(t){return"Ok"===this.tag?t.Ok(this.value):t.Error(this.value)},n.isOk=function(){return"Ok"===this.tag},n.isError=function(){return"Error"===this.tag},n.toOption=function(){return"Ok"===this.tag?o.Some(this.value):o.None()},t}();h.prototype.__boxed_type__="Result";var g=Object.create(null,Object.getOwnPropertyDescriptors(h.prototype)),p={Ok:function(t){var n=Object.create(g);return n.tag="Ok",n.value=t,n},Error:function(t){var n=Object.create(g);return n.tag="Error",n.value=t,n},fromExecution:function(t){try{return p.Ok(t())}catch(t){return p.Error(t)}},fromPromise:function(t){try{return Promise.resolve(function(n,e){try{var r=Promise.resolve(t).then(function(t){return p.Ok(t)})}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}(0,function(t){return p.Error(t)}))}catch(t){return Promise.reject(t)}},equals:function(t,n,e){return t.tag===n.tag&&("Error"===t.tag&&"Error"===n.tag||e(t.value,n.value))},pattern:{Ok:function(t){return{tag:"Ok",value:t}},Error:function(t){return{tag:"Error",value:t}}}};function d(t){var n=this,e={};this.tag="Pending",this.pending=e,e.cancel=t(function(t){if("Pending"===n.tag){var e=n.pending.resolveCallbacks;null==e||e.forEach(function(n){return n(t)}),n.tag="Resolved",n.value=t,n.pending=void 0}})}var _=Object.create(null,Object.getOwnPropertyDescriptors(/*#__PURE__*/function(){function t(t){this.tag=void 0,this.value=void 0,this.pending=void 0,this.tag="Pending",this.pending={}}var n=t.prototype;return n.isPending=function(){return"Pending"===this.tag},n.isCancelled=function(){return"Cancelled"===this.tag},n.isResolved=function(){return"Resolved"===this.tag},n.get=function(t){if(this.isPending()){var n,e=this.pending;e.resolveCallbacks=null!=(n=e.resolveCallbacks)?n:[],e.resolveCallbacks.push(t)}this.isResolved()&&t(this.value)},n.onCancel=function(t){if(this.isPending()){var n,e=this.pending;e.cancelCallbacks=null!=(n=e.cancelCallbacks)?n:[],e.cancelCallbacks.push(t)}this.isCancelled()&&t()},n.cancel=function(){if("Pending"===this.tag){this.tag="Cancelled",this.value=void 0;var t=this.pending,n=t.cancelCallbacks;null==t.cancel||t.cancel(),null==n||n.forEach(function(t){return t()}),this.pending=void 0}},n.map=function(t,n){var e=this;void 0===n&&(n=!1);var r=m.make(function(r){if(e.get(function(n){r(t(n))}),n)return function(){e.cancel()}});return this.onCancel(function(){r.cancel()}),r},n.then=function(t){return this.get(t),this},n.flatMap=function(t,n){var e=this;void 0===n&&(n=!1);var r=m.make(function(o){if(e.get(function(n){var e=t(n);e.get(o),e.onCancel(function(){return r.cancel()})}),n)return function(){e.cancel()}});return this.onCancel(function(){r.cancel()}),r},n.tap=function(t){return this.get(t),this},n.tapOk=function(t){return this.get(function(n){n.match({Ok:function(n){return t(n)},Error:function(){}})}),this},n.tapError=function(t){return this.get(function(n){n.match({Ok:function(){},Error:function(n){return t(n)}})}),this},n.mapResult=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return n}})},n)},n.mapOk=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(n){return p.Ok(t(n))},Error:function(){return n}})},n)},n.mapError=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(){return n},Error:function(n){return p.Error(t(n))}})},n)},n.flatMapOk=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return m.value(n)}})},n)},n.flatMapError=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(){return m.value(n)},Error:function(n){return t(n)}})},n)},n.toPromise=function(){var t=this;return new Promise(function(n){t.get(n)})},n.resultToPromise=function(){var t=this;return new Promise(function(n,e){t.get(function(t){t.match({Ok:n,Error:e})})})},t}().prototype)),m={make:function(t){var n=Object.create(_);return d.call(n,t),n},value:function(t){var n=Object.create(_);return d.call(n,function(n){return n(t)}),n},fromPromise:function(t){return m.make(function(n){t.then(function(t){return n(p.Ok(t))},function(t){return n(p.Error(t))})})},all:function(t,n){void 0===n&&(n=!1);for(var e=t.length,r=m.value([]),o=0,u=function(){if(o>=e)return{v:r};var u=r;r=t[o].flatMap(function(t){return u.map(function(n){return n.push(t),n},n)},n),o++};;){var i=u();if("object"==typeof i)return i.v}}},O={make:function(){var t=void 0;return[m.make(function(n){t=n}),t]}},k={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},y=Symbol.for("NOT_COMPUTED"),b={__proto__:null,Lazy:function(t){var n={contents:y};return{get value(){return n.contents===y&&(n.contents=t()),n.contents}}}},N={__proto__:null,encode:function(t,n){return JSON.stringify(t,function(t,n){if(null!=n)return"Option"===n.__boxed_type__?{__boxed_type__:"Option",tag:n.tag,value:n.value}:"Result"===n.__boxed_type__?{__boxed_type__:"Result",tag:n.tag,value:n.value}:"AsyncData"===n.__boxed_type__?{__boxed_type__:"AsyncData",tag:n.tag,value:n.value}:n},n)},decode:function(t){return JSON.parse(t,function(t,n){return null==n?n:"Option"===n.__boxed_type__?"Some"===n.tag?o.Some(n.value):o.None():"Result"===n.__boxed_type__?"Ok"===n.tag?p.Ok(n.value):p.Error(n.value):"AsyncData"===n.__boxed_type__?"NotAsked"===n.tag?v.NotAsked():"Loading"===n.tag?v.Loading():v.Done(n.value):n})}};exports.Array=i,exports.AsyncData=v,exports.Deferred=O,exports.Dict=k,exports.Future=m,exports.Lazy=b,exports.Option=o,exports.Result=p,exports.Serializer=N; | ||
var t=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag="None",this.value=void 0}var n=t.prototype;return n.map=function(t){return"Some"===this.tag?o.Some(t(this.value)):this},n.flatMap=function(t){return"Some"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Some"===this.tag?this.value:t},n.match=function(t){return"Some"===this.tag?t.Some(this.value):t.None()},n.toUndefined=function(){return"None"===this.tag?void 0:this.value},n.toNull=function(){return"None"===this.tag?null:this.value},n.isSome=function(){return"Some"===this.tag},n.isNone=function(){return"None"===this.tag},t}();t.prototype.__boxed_type__="Option";var n,e=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),r=((n=Object.create(e)).tag="None",n.value=void 0,n),o={Some:function(t){var n=Object.create(e);return n.tag="Some",n.value=t,n},None:function(){return r},fromNullable:function(t){return null==t?o.None():o.Some(t)},fromNull:function(t){return null===t?o.None():o.Some(t)},fromUndefined:function(t){return void 0===t?o.None():o.Some(t)},equals:function(t,n,e){return"Some"===t.tag&&"Some"===n.tag?e(t.value,n.value):t.tag===n.tag},pattern:{Some:function(t){return{tag:"Some",value:t}},None:{tag:"None"}}},i=function(t,n){return t===n?0:t>n?1:-1},u={__proto__:null,from:Array.from,of:Array.of,isArray:Array.isArray,keepMap:function(t,n){var e=[];return t.forEach(function(t){var r=n(t);null!=r&&e.push(r)}),e},getBy:function(t,n){for(var e=-1;++e<t.length;){var r=t[e];if(n(r))return o.Some(r)}return o.None()},getIndexBy:function(t,n){for(var e=-1;++e<t.length;)if(n(t[e]))return o.Some(e);return o.None()},binarySearchBy:function(t,n,e){if(void 0===e&&(e=i),0===t.length)return-1;for(var r=0,o=t.length-1;;){var u=r+(o-r)/2|0;if(u===r||u===o)return o;var a=e(n,t[u]);if(0===a)return u;a>0?r=u:a<0&&(o=u)}}},a=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag="NotAsked",this.value=void 0}var n=t.prototype;return n.map=function(t){return"Done"===this.tag?v.Done(t(this.value)):this},n.flatMap=function(t){return"Done"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Done"===this.tag?this.value:t},n.match=function(t){return"Done"===this.tag?t.Done(this.value):"Loading"===this.tag?t.Loading():t.NotAsked()},n.isDone=function(){return"Done"===this.tag},n.isLoading=function(){return"Loading"===this.tag},n.isNotAsked=function(){return"NotAsked"===this.tag},n.toOption=function(){return"Done"===this.tag?o.Some(this.value):o.None()},t}();a.prototype.__boxed_type__="AsyncData";var c,s=Object.create(null,Object.getOwnPropertyDescriptors(a.prototype)),l=((c=Object.create(s)).tag="Loading",c.value=void 0,c),f=function(){var t=Object.create(s);return t.tag="NotAsked",t.value=void 0,t}(),v={Done:function(t){var n=Object.create(s);return n.tag="Done",n.value=t,n},Loading:function(){return l},NotAsked:function(){return f},equals:function(t,n,e){return"Done"===t.tag&&"Done"===n.tag?e(t.value,n.value):t.tag===n.tag},pattern:{Done:function(t){return{tag:"Done",value:t}},NotAsked:{tag:"NotAsked"},Loading:{tag:"Loading"}}},h=/*#__PURE__*/function(){function t(){this.tag=void 0,this.value=void 0,this.tag=void 0,this.value=void 0}var n=t.prototype;return n.map=function(t){return"Ok"===this.tag?p.Ok(t(this.value)):this},n.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},n.getWithDefault=function(t){return"Ok"===this.tag?this.value:t},n.match=function(t){return"Ok"===this.tag?t.Ok(this.value):t.Error(this.value)},n.isOk=function(){return"Ok"===this.tag},n.isError=function(){return"Error"===this.tag},n.toOption=function(){return"Ok"===this.tag?o.Some(this.value):o.None()},t}();h.prototype.__boxed_type__="Result";var g=Object.create(null,Object.getOwnPropertyDescriptors(h.prototype)),p={Ok:function(t){var n=Object.create(g);return n.tag="Ok",n.value=t,n},Error:function(t){var n=Object.create(g);return n.tag="Error",n.value=t,n},fromExecution:function(t){try{return p.Ok(t())}catch(t){return p.Error(t)}},fromPromise:function(t){try{return Promise.resolve(function(n,e){try{var r=Promise.resolve(t).then(function(t){return p.Ok(t)})}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}(0,function(t){return p.Error(t)}))}catch(t){return Promise.reject(t)}},equals:function(t,n,e){return t.tag===n.tag&&("Error"===t.tag&&"Error"===n.tag||e(t.value,n.value))},pattern:{Ok:function(t){return{tag:"Ok",value:t}},Error:function(t){return{tag:"Error",value:t}}}};function d(t){var n=this,e={};this.tag="Pending",this.pending=e,e.cancel=t(function(t){if("Pending"===n.tag){var e=n.pending.resolveCallbacks;null==e||e.forEach(function(n){return n(t)}),n.tag="Resolved",n.value=t,n.pending=void 0}})}var _=Object.create(null,Object.getOwnPropertyDescriptors(/*#__PURE__*/function(){function t(t){this.tag=void 0,this.value=void 0,this.pending=void 0,this.tag="Pending",this.pending={}}var n=t.prototype;return n.isPending=function(){return"Pending"===this.tag},n.isCancelled=function(){return"Cancelled"===this.tag},n.isResolved=function(){return"Resolved"===this.tag},n.get=function(t){if(this.isPending()){var n,e=this.pending;e.resolveCallbacks=null!=(n=e.resolveCallbacks)?n:[],e.resolveCallbacks.push(t)}this.isResolved()&&t(this.value)},n.onCancel=function(t){if(this.isPending()){var n,e=this.pending;e.cancelCallbacks=null!=(n=e.cancelCallbacks)?n:[],e.cancelCallbacks.push(t)}this.isCancelled()&&t()},n.cancel=function(){if("Pending"===this.tag){this.tag="Cancelled",this.value=void 0;var t=this.pending,n=t.cancelCallbacks;null==t.cancel||t.cancel(),null==n||n.forEach(function(t){return t()}),this.pending=void 0}},n.map=function(t,n){var e=this;void 0===n&&(n=!1);var r=m.make(function(r){if(e.get(function(n){r(t(n))}),n)return function(){e.cancel()}});return this.onCancel(function(){r.cancel()}),r},n.then=function(t){return this.get(t),this},n.flatMap=function(t,n){var e=this;void 0===n&&(n=!1);var r=m.make(function(o){if(e.get(function(n){var e=t(n);e.get(o),e.onCancel(function(){return r.cancel()})}),n)return function(){e.cancel()}});return this.onCancel(function(){r.cancel()}),r},n.tap=function(t){return this.get(t),this},n.tapOk=function(t){return this.get(function(n){n.match({Ok:function(n){return t(n)},Error:function(){}})}),this},n.tapError=function(t){return this.get(function(n){n.match({Ok:function(){},Error:function(n){return t(n)}})}),this},n.mapResult=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return n}})},n)},n.mapOk=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(n){return p.Ok(t(n))},Error:function(){return n}})},n)},n.mapError=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Ok:function(){return n},Error:function(n){return p.Error(t(n))}})},n)},n.flatMapOk=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return m.value(n)}})},n)},n.flatMapError=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(){return m.value(n)},Error:function(n){return t(n)}})},n)},n.toPromise=function(){var t=this;return new Promise(function(n){t.get(n)})},n.resultToPromise=function(){var t=this;return new Promise(function(n,e){t.get(function(t){t.match({Ok:n,Error:e})})})},t}().prototype)),m={make:function(t){var n=Object.create(_);return d.call(n,t),n},value:function(t){var n=Object.create(_);return d.call(n,function(n){return n(t)}),n},fromPromise:function(t){return m.make(function(n){t.then(function(t){return n(p.Ok(t))},function(t){return n(p.Error(t))})})},all:function(t,n){void 0===n&&(n=!1);for(var e=t.length,r=m.value([]),o=0,i=function(){if(o>=e)return{v:r};var i=r;r=t[o].flatMap(function(t){return i.map(function(n){return n.push(t),n},n)},n),o++};;){var u=i();if("object"==typeof u)return u.v}}},O={make:function(){var t=void 0;return[m.make(function(n){t=n}),t]}},k={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},y=Symbol.for("NOT_COMPUTED"),b={__proto__:null,Lazy:function(t){var n={contents:y};return{get value(){return n.contents===y&&(n.contents=t()),n.contents}}}},N={__proto__:null,encode:function(t,n){return JSON.stringify(t,function(t,n){if(null!=n)return"Option"===n.__boxed_type__?{__boxed_type__:"Option",tag:n.tag,value:n.value}:"Result"===n.__boxed_type__?{__boxed_type__:"Result",tag:n.tag,value:n.value}:"AsyncData"===n.__boxed_type__?{__boxed_type__:"AsyncData",tag:n.tag,value:n.value}:n},n)},decode:function(t){return JSON.parse(t,function(t,n){return null==n?n:"Option"===n.__boxed_type__?"Some"===n.tag?o.Some(n.value):o.None():"Result"===n.__boxed_type__?"Ok"===n.tag?p.Ok(n.value):p.Error(n.value):"AsyncData"===n.__boxed_type__?"NotAsked"===n.tag?v.NotAsked():"Loading"===n.tag?v.Loading():v.Done(n.value):n})}};exports.Array=u,exports.AsyncData=v,exports.Deferred=O,exports.Dict=k,exports.Future=m,exports.Lazy=b,exports.Option=o,exports.Result=p,exports.Serializer=N; | ||
//# sourceMappingURL=Boxed.js.map |
{ | ||
"name": "@swan-io/boxed", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Utility types for functional TypeScript", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
104092
317