@swan-io/boxed
Advanced tools
Comparing version 0.3.7 to 0.4.0
import { Option } from "./Option"; | ||
export declare type AsyncData<Value> = AsyncDataClass<Value> & ({ | ||
tag: "NotAsked"; | ||
value: undefined; | ||
} | { | ||
tag: "Loading"; | ||
value: undefined; | ||
} | { | ||
tag: "Done"; | ||
value: Value; | ||
}); | ||
declare class AsyncDataClass<Value> { | ||
export declare class AsyncData<Value> { | ||
/** | ||
* Create an AsyncData.Done value | ||
*/ | ||
static Done: <Value_1>(value: Value_1) => AsyncData<Value_1>; | ||
/** | ||
* Create an AsyncData.Loading value | ||
*/ | ||
static Loading: <Value_1>() => AsyncData<Value_1>; | ||
/** | ||
* Create an AsyncData.NotAsked value | ||
*/ | ||
static NotAsked: <Value_1>() => AsyncData<Value_1>; | ||
/** | ||
* Turns an array of asyncData into an asyncData of array | ||
*/ | ||
static all: <AsyncDatas extends [] | readonly AsyncData<any>[]>(asyncDatas: AsyncDatas) => AsyncData<{ -readonly [P in keyof AsyncDatas]: AsyncDatas[P] extends AsyncData<infer V> ? V : never; }>; | ||
static equals: <Value_1>(a: AsyncData<Value_1>, b: AsyncData<Value_1>, equals: (a: Value_1, b: Value_1) => boolean) => boolean; | ||
static pattern: { | ||
Done: <T>(x: T) => { | ||
readonly tag: "Done"; | ||
readonly value: T; | ||
}; | ||
NotAsked: { | ||
readonly tag: "NotAsked"; | ||
}; | ||
Loading: { | ||
readonly tag: "Loading"; | ||
}; | ||
}; | ||
tag: "NotAsked" | "Loading" | "Done"; | ||
value: Value | undefined; | ||
constructor(); | ||
map<ReturnValue>(f: (value: Value) => ReturnValue): AsyncData<ReturnValue>; | ||
flatMap<ReturnValue>(f: (value: Value) => AsyncData<ReturnValue>): AsyncData<ReturnValue>; | ||
getWithDefault(defaultValue: Value): Value; | ||
match<ReturnValue>(config: { | ||
/** | ||
* Returns the AsyncData containing the value from the callback | ||
* | ||
* (AsyncData\<A>, A => B) => AsyncData\<B> | ||
*/ | ||
map<ReturnValue>(this: AsyncData<Value>, f: (value: Value) => ReturnValue): AsyncData<ReturnValue>; | ||
/** | ||
* Returns the AsyncData containing the value from the callback | ||
* | ||
* (AsyncData\<A>, A => AsyncData\<B>) => AsyncData\<B> | ||
*/ | ||
flatMap<ReturnValue>(this: AsyncData<Value>, f: (value: Value) => AsyncData<ReturnValue>): AsyncData<ReturnValue>; | ||
/** | ||
* Return the value if present, and the fallback otherwise | ||
* | ||
* (AsyncData\<A>, A) => A | ||
*/ | ||
getWithDefault(this: AsyncData<Value>, defaultValue: Value): Value; | ||
/** | ||
* Explodes the AsyncData given its case | ||
*/ | ||
match<ReturnValue>(this: AsyncData<Value>, config: { | ||
Done: (value: Value) => ReturnValue; | ||
@@ -24,36 +61,33 @@ Loading: () => ReturnValue; | ||
}): ReturnValue; | ||
/** | ||
* Runs the callback and returns `this` | ||
*/ | ||
tap(this: AsyncData<Value>, func: (asyncData: AsyncData<Value>) => unknown): AsyncData<Value>; | ||
isDone(): this is AsyncDataClass<Value> & { | ||
/** | ||
* Typeguard | ||
*/ | ||
isDone(): this is AsyncData<Value> & { | ||
tag: "Done"; | ||
value: Value; | ||
}; | ||
isLoading(): this is AsyncDataClass<Value> & { | ||
/** | ||
* Typeguard | ||
*/ | ||
isLoading(): this is AsyncData<Value> & { | ||
tag: "Loading"; | ||
value: undefined; | ||
}; | ||
isNotAsked(): this is AsyncDataClass<Value> & { | ||
/** | ||
* Typeguard | ||
*/ | ||
isNotAsked(): this is AsyncData<Value> & { | ||
tag: "NotAsked"; | ||
value: undefined; | ||
}; | ||
/** | ||
* Return an option of the value | ||
* | ||
* (AsyncData\<A>) => Option\<A> | ||
*/ | ||
toOption(): Option<Value>; | ||
} | ||
export declare const AsyncData: { | ||
Done: <Value>(value: Value) => AsyncData<Value>; | ||
Loading: <Value_1>() => AsyncData<Value_1>; | ||
NotAsked: <Value_2>() => AsyncData<Value_2>; | ||
all: <AsyncDatas extends [] | readonly AsyncData<any>[]>(asyncDatas: AsyncDatas) => AsyncData<{ -readonly [P in keyof AsyncDatas]: AsyncDatas[P] extends AsyncData<infer V> ? V : never; }>; | ||
equals: <Value_3>(a: AsyncData<Value_3>, b: AsyncData<Value_3>, equals: (a: Value_3, b: Value_3) => boolean) => boolean; | ||
pattern: { | ||
Done: <T>(x: T) => { | ||
readonly tag: "Done"; | ||
readonly value: T; | ||
}; | ||
NotAsked: { | ||
readonly tag: "NotAsked"; | ||
}; | ||
Loading: { | ||
readonly tag: "Loading"; | ||
}; | ||
}; | ||
}; | ||
export {}; |
@@ -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.tap=function(t){return t(this),this},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)},all:function(t){for(var n=t.length,e=o.Some([]),r=0,u=function(){if(r>=n)return{v:e};var o=t[r];e=e.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),r++};;){var i=u();if("object"==typeof i)return i.v}},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,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=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.tap=function(t){return t(this),this},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,f=Object.create(null,Object.getOwnPropertyDescriptors(a.prototype)),s=((c=Object.create(f)).tag="Loading",c.value=void 0,c),l=function(){var t=Object.create(f);return t.tag="NotAsked",t.value=void 0,t}(),v={Done:function(t){var n=Object.create(f);return n.tag="Done",n.value=t,n},Loading:function(){return s},NotAsked:function(){return l},all:function(t){for(var n=t.length,e=v.Done([]),r=0,o=function(){if(r>=n)return{v:e};var o=t[r];e=e.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),r++};;){var u=o();if("object"==typeof u)return u.v}},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.mapError=function(t){return"Ok"===this.tag?this:p.Error(t(this.value))},n.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},n.flatMapError=function(t){return"Ok"===this.tag?this:t(this.value)},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.tap=function(t){return t(this),this},n.tapOk=function(t){return"Ok"===this.tag&&t(this.value),this},n.tapError=function(t){return"Error"===this.tag&&t(this.value),this},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)}},all:function(t){for(var n=t.length,e=p.Ok([]),r=0,o=function(){if(r>=n)return{v:e};var o=t[r];e=e.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),r++};;){var u=o();if("object"==typeof u)return u.v}},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 m=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=_.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=_.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 _.value(n)}})},n)},n.flatMapError=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(){return _.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)),_={make:function(t){var n=Object.create(m);return d.call(n,t),n},value:function(t){var n=Object.create(m);return d.call(n,function(n){return n(t)}),n},fromPromise:function(t){return _.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=_.value([]),o=0,u=function(){if(o>=e)return{v:r};var u=t[o];r=r.flatMap(function(t){return u.map(function(n){return t.push(n),t},n)},n),o++};;){var i=u();if("object"==typeof i)return i.v}}},O={make:function(){var t=void 0;return[_.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=function(t){var n={contents:y};return{get value(){return n.contents===y&&(n.contents=t()),n.contents}}},E={__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})}};export{i as Array,v as AsyncData,O as Deferred,k as Dict,_ as Future,b as Lazy,o as Option,p as Result,E 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(n){return"Some"===this.tag?t.Some(n(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.tap=function(t){return t(this),this},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.Some=function(t){var n=Object.create(r);return n.tag="Some",n.value=t,n},t.None=function(){return e},t.fromNullable=function(n){return null==n?t.None():t.Some(n)},t.fromNull=function(n){return null===n?t.None():t.Some(n)},t.fromUndefined=function(n){return void 0===n?t.None():t.Some(n)},t.all=function(n){for(var r=n.length,e=t.Some([]),o=0,i=function(){if(o>=r)return{v:e};var t=n[o];e=e.flatMap(function(n){return t.map(function(t){return n.push(t),n})}),o++};;){var u=i();if("object"==typeof u)return u.v}},t.equals=function(t,n,r){return t.isSome()&&n.isSome()?r(t.value,n.value):t.tag===n.tag},t.pattern={Some:function(t){return{tag:"Some",value:t}},None:{tag:"None"}},t.prototype.__boxed_type__="Option";var n,r=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),e=((n=Object.create(r)).tag="None",n.value=void 0,n),o=function(t,n){return t===n?0:t>n?1:-1},i={__proto__:null,from:Array.from,of:Array.of,isArray:Array.isArray,keepMap:function(t,n){var r=[];return t.forEach(function(t){var e=n(t);null!=e&&r.push(e)}),r},getBy:function(n,r){for(var e=-1;++e<n.length;){var o=n[e];if(r(o))return t.Some(o)}return t.None()},getIndexBy:function(n,r){for(var e=-1;++e<n.length;)if(r(n[e]))return t.Some(e);return t.None()},binarySearchBy:function(t,n,r){if(void 0===r&&(r=o),0===t.length)return-1;for(var e=0,i=t.length-1;;){var u=e+(i-e)/2|0;if(u===e||u===i)return i;var a=r(n,t[u]);if(0===a)return u;a>0?e=u:a<0&&(i=u)}}},u=/*#__PURE__*/function(){function n(){this.tag=void 0,this.value=void 0,this.tag="NotAsked",this.value=void 0}var r=n.prototype;return r.map=function(t){return"Done"===this.tag?n.Done(t(this.value)):this},r.flatMap=function(t){return"Done"===this.tag?t(this.value):this},r.getWithDefault=function(t){return"Done"===this.tag?this.value:t},r.match=function(t){return"Done"===this.tag?t.Done(this.value):"Loading"===this.tag?t.Loading():t.NotAsked()},r.tap=function(t){return t(this),this},r.isDone=function(){return"Done"===this.tag},r.isLoading=function(){return"Loading"===this.tag},r.isNotAsked=function(){return"NotAsked"===this.tag},r.toOption=function(){return"Done"===this.tag?t.Some(this.value):t.None()},n}();u.Done=function(t){var n=Object.create(c);return n.tag="Done",n.value=t,n},u.Loading=function(){return s},u.NotAsked=function(){return f},u.all=function(t){for(var n=t.length,r=u.Done([]),e=0,o=function(){if(e>=n)return{v:r};var o=t[e];r=r.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),e++};;){var i=o();if("object"==typeof i)return i.v}},u.equals=function(t,n,r){return t.isDone()&&n.isDone()?r(t.value,n.value):t.tag===n.tag},u.pattern={Done:function(t){return{tag:"Done",value:t}},NotAsked:{tag:"NotAsked"},Loading:{tag:"Loading"}},u.prototype.__boxed_type__="AsyncData";var a,c=Object.create(null,Object.getOwnPropertyDescriptors(u.prototype)),s=((a=Object.create(c)).tag="Loading",a.value=void 0,a),f=function(){var t=Object.create(c);return t.tag="NotAsked",t.value=void 0,t}(),l=/*#__PURE__*/function(){function n(){this.tag=void 0,this.value=void 0,this.error=void 0,this.tag=void 0,this.value=void 0,this.error=void 0}n.fromPromise=function(t){try{return Promise.resolve(function(r,e){try{var o=Promise.resolve(t).then(function(t){return n.Ok(t)})}catch(t){return e(t)}return o&&o.then?o.then(void 0,e):o}(0,function(t){return n.Error(t)}))}catch(t){return Promise.reject(t)}};var r=n.prototype;return r.map=function(t){return"Ok"===this.tag?n.Ok(t(this.value)):this},r.mapError=function(t){return"Ok"===this.tag?this:n.Error(t(this.error))},r.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},r.flatMapError=function(t){return"Ok"===this.tag?this:t(this.error)},r.getWithDefault=function(t){return"Ok"===this.tag?this.value:t},r.match=function(t){return"Ok"===this.tag?t.Ok(this.value):t.Error(this.error)},r.tap=function(t){return t(this),this},r.tapOk=function(t){return this.isOk()&&t(this.value),this},r.tapError=function(t){return this.isError()&&t(this.error),this},r.isOk=function(){return"Ok"===this.tag},r.isError=function(){return"Error"===this.tag},r.toOption=function(){return"Ok"===this.tag?t.Some(this.value):t.None()},n}();l.Ok=function(t){var n=Object.create(h);return n.tag="Ok",n.value=t,n},l.Error=function(t){var n=Object.create(h);return n.tag="Error",n.error=t,n},l.fromExecution=function(t){try{return l.Ok(t())}catch(t){return l.Error(t)}},l.all=function(t){for(var n=t.length,r=l.Ok([]),e=0,o=function(){if(e>=n)return{v:r};var o=t[e];r=r.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),e++};;){var i=o();if("object"==typeof i)return i.v}},l.equals=function(t,n,r){return t.tag===n.tag&&("Error"===t.tag&&"Error"===n.tag||r(t.value,n.value))},l.pattern={Ok:function(t){return{tag:"Ok",value:t}},Error:function(t){return{tag:"Error",error:t}}},l.prototype.__boxed_type__="Result";var h=Object.create(null,Object.getOwnPropertyDescriptors(l.prototype));function v(t){var n=this,r={};this.tag="Pending",this.pending=r,r.cancel=t(function(t){if("Pending"===n.tag){var r=n.pending.resolveCallbacks;null==r||r.forEach(function(n){return n(t)}),n.tag="Resolved",n.value=t,n.pending=void 0}})}var g=/*#__PURE__*/function(){function t(t){this.tag=void 0,this.value=void 0,this.pending=void 0,this.tag="Pending",this.pending={}}t.fromPromise=function(n){return t.make(function(t){n.then(function(n){return t(l.Ok(n))},function(n){return t(l.Error(n))})})};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,r=this.pending;r.resolveCallbacks=null!=(n=r.resolveCallbacks)?n:[],r.resolveCallbacks.push(t)}this.isResolved()&&t(this.value)},n.onCancel=function(t){if(this.isPending()){var n,r=this.pending;r.cancelCallbacks=null!=(n=r.cancelCallbacks)?n:[],r.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(n,r){var e=this;void 0===r&&(r=!1);var o=t.make(function(t){if(e.get(function(r){t(n(r))}),r)return function(){e.cancel()}});return this.onCancel(function(){o.cancel()}),o},n.then=function(t){return this.get(t),this},n.flatMap=function(n,r){var e=this;void 0===r&&(r=!1);var o=t.make(function(t){if(e.get(function(r){var e=n(r);e.get(t),e.onCancel(function(){return o.cancel()})}),r)return function(){e.cancel()}});return this.onCancel(function(){o.cancel()}),o},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 l.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 l.Error(t(n))}})},n)},n.flatMapOk=function(n,r){return void 0===r&&(r=!1),this.flatMap(function(r){return r.match({Ok:function(t){return n(t)},Error:function(){return t.value(r)}})},r)},n.flatMapError=function(n,r){return void 0===r&&(r=!1),this.flatMap(function(r){return r.match({Ok:function(){return t.value(r)},Error:function(t){return n(t)}})},r)},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,r){t.get(function(t){t.match({Ok:n,Error:r})})})},t}();g.make=function(t){var n=Object.create(p);return v.call(n,t),n},g.value=function(t){var n=Object.create(p);return v.call(n,function(n){return n(t)}),n},g.all=function(t,n){void 0===n&&(n=!1);for(var r=t.length,e=g.value([]),o=0,i=function(){if(o>=r)return{v:e};var i=t[o];e=e.flatMap(function(t){return i.map(function(n){return t.push(n),t},n)},n),o++};;){var u=i();if("object"==typeof u)return u.v}};var p=Object.create(null,Object.getOwnPropertyDescriptors(g.prototype)),d={make:function(){var t=void 0;return[g.make(function(n){t=n}),t]}},_={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},m=Symbol.for("NOT_COMPUTED"),O=function(t){var n={contents:m};return{get value(){return n.contents===m&&(n.contents=t()),n.contents}}},k={__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__?"Error"===n.tag?{__boxed_type__:"Result",tag:n.tag,error:n.error}:{__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(n){return JSON.parse(n,function(n,r){return null==r?r:"Option"===r.__boxed_type__?"Some"===r.tag?t.Some(r.value):t.None():"Result"===r.__boxed_type__?"Ok"===r.tag?l.Ok(r.value):l.Error(r.error):"AsyncData"===r.__boxed_type__?"NotAsked"===r.tag?u.NotAsked():"Loading"===r.tag?u.Loading():u.Done(r.value):r})}};export{i as Array,u as AsyncData,d as Deferred,_ as Dict,g as Future,O as Lazy,t as Option,l as Result,k 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.tap=function(t){return t(this),this},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)},all:function(t){for(var n=t.length,e=o.Some([]),r=0,i=function(){if(r>=n)return{v:e};var o=t[r];e=e.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),r++};;){var u=i();if("object"==typeof u)return u.v}},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.tap=function(t){return t(this),this},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)),f=((c=Object.create(s)).tag="Loading",c.value=void 0,c),l=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 f},NotAsked:function(){return l},all:function(t){for(var n=t.length,e=v.Done([]),r=0,o=function(){if(r>=n)return{v:e};var o=t[r];e=e.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),r++};;){var i=o();if("object"==typeof i)return i.v}},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.mapError=function(t){return"Ok"===this.tag?this:p.Error(t(this.value))},n.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},n.flatMapError=function(t){return"Ok"===this.tag?this:t(this.value)},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.tap=function(t){return t(this),this},n.tapOk=function(t){return"Ok"===this.tag&&t(this.value),this},n.tapError=function(t){return"Error"===this.tag&&t(this.value),this},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)}},all:function(t){for(var n=t.length,e=p.Ok([]),r=0,o=function(){if(r>=n)return{v:e};var o=t[r];e=e.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),r++};;){var i=o();if("object"==typeof i)return i.v}},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 m=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=_.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=_.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 _.value(n)}})},n)},n.flatMapError=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(){return _.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)),_={make:function(t){var n=Object.create(m);return d.call(n,t),n},value:function(t){var n=Object.create(m);return d.call(n,function(n){return n(t)}),n},fromPromise:function(t){return _.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=_.value([]),o=0,i=function(){if(o>=e)return{v:r};var i=t[o];r=r.flatMap(function(t){return i.map(function(n){return t.push(n),t},n)},n),o++};;){var u=i();if("object"==typeof u)return u.v}}},O={make:function(){var t=void 0;return[_.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,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=_,exports.Lazy=function(t){var n={contents:y};return{get value(){return n.contents===y&&(n.contents=t()),n.contents}}},exports.Option=o,exports.Result=p,exports.Serializer=b; | ||
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(n){return"Some"===this.tag?t.Some(n(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.tap=function(t){return t(this),this},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.Some=function(t){var n=Object.create(r);return n.tag="Some",n.value=t,n},t.None=function(){return e},t.fromNullable=function(n){return null==n?t.None():t.Some(n)},t.fromNull=function(n){return null===n?t.None():t.Some(n)},t.fromUndefined=function(n){return void 0===n?t.None():t.Some(n)},t.all=function(n){for(var r=n.length,e=t.Some([]),o=0,i=function(){if(o>=r)return{v:e};var t=n[o];e=e.flatMap(function(n){return t.map(function(t){return n.push(t),n})}),o++};;){var u=i();if("object"==typeof u)return u.v}},t.equals=function(t,n,r){return t.isSome()&&n.isSome()?r(t.value,n.value):t.tag===n.tag},t.pattern={Some:function(t){return{tag:"Some",value:t}},None:{tag:"None"}},t.prototype.__boxed_type__="Option";var n,r=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),e=((n=Object.create(r)).tag="None",n.value=void 0,n),o=function(t,n){return t===n?0:t>n?1:-1},i={__proto__:null,from:Array.from,of:Array.of,isArray:Array.isArray,keepMap:function(t,n){var r=[];return t.forEach(function(t){var e=n(t);null!=e&&r.push(e)}),r},getBy:function(n,r){for(var e=-1;++e<n.length;){var o=n[e];if(r(o))return t.Some(o)}return t.None()},getIndexBy:function(n,r){for(var e=-1;++e<n.length;)if(r(n[e]))return t.Some(e);return t.None()},binarySearchBy:function(t,n,r){if(void 0===r&&(r=o),0===t.length)return-1;for(var e=0,i=t.length-1;;){var u=e+(i-e)/2|0;if(u===e||u===i)return i;var a=r(n,t[u]);if(0===a)return u;a>0?e=u:a<0&&(i=u)}}},u=/*#__PURE__*/function(){function n(){this.tag=void 0,this.value=void 0,this.tag="NotAsked",this.value=void 0}var r=n.prototype;return r.map=function(t){return"Done"===this.tag?n.Done(t(this.value)):this},r.flatMap=function(t){return"Done"===this.tag?t(this.value):this},r.getWithDefault=function(t){return"Done"===this.tag?this.value:t},r.match=function(t){return"Done"===this.tag?t.Done(this.value):"Loading"===this.tag?t.Loading():t.NotAsked()},r.tap=function(t){return t(this),this},r.isDone=function(){return"Done"===this.tag},r.isLoading=function(){return"Loading"===this.tag},r.isNotAsked=function(){return"NotAsked"===this.tag},r.toOption=function(){return"Done"===this.tag?t.Some(this.value):t.None()},n}();u.Done=function(t){var n=Object.create(c);return n.tag="Done",n.value=t,n},u.Loading=function(){return s},u.NotAsked=function(){return f},u.all=function(t){for(var n=t.length,r=u.Done([]),e=0,o=function(){if(e>=n)return{v:r};var o=t[e];r=r.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),e++};;){var i=o();if("object"==typeof i)return i.v}},u.equals=function(t,n,r){return t.isDone()&&n.isDone()?r(t.value,n.value):t.tag===n.tag},u.pattern={Done:function(t){return{tag:"Done",value:t}},NotAsked:{tag:"NotAsked"},Loading:{tag:"Loading"}},u.prototype.__boxed_type__="AsyncData";var a,c=Object.create(null,Object.getOwnPropertyDescriptors(u.prototype)),s=((a=Object.create(c)).tag="Loading",a.value=void 0,a),f=function(){var t=Object.create(c);return t.tag="NotAsked",t.value=void 0,t}(),l=/*#__PURE__*/function(){function n(){this.tag=void 0,this.value=void 0,this.error=void 0,this.tag=void 0,this.value=void 0,this.error=void 0}n.fromPromise=function(t){try{return Promise.resolve(function(r,e){try{var o=Promise.resolve(t).then(function(t){return n.Ok(t)})}catch(t){return e(t)}return o&&o.then?o.then(void 0,e):o}(0,function(t){return n.Error(t)}))}catch(t){return Promise.reject(t)}};var r=n.prototype;return r.map=function(t){return"Ok"===this.tag?n.Ok(t(this.value)):this},r.mapError=function(t){return"Ok"===this.tag?this:n.Error(t(this.error))},r.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},r.flatMapError=function(t){return"Ok"===this.tag?this:t(this.error)},r.getWithDefault=function(t){return"Ok"===this.tag?this.value:t},r.match=function(t){return"Ok"===this.tag?t.Ok(this.value):t.Error(this.error)},r.tap=function(t){return t(this),this},r.tapOk=function(t){return this.isOk()&&t(this.value),this},r.tapError=function(t){return this.isError()&&t(this.error),this},r.isOk=function(){return"Ok"===this.tag},r.isError=function(){return"Error"===this.tag},r.toOption=function(){return"Ok"===this.tag?t.Some(this.value):t.None()},n}();l.Ok=function(t){var n=Object.create(h);return n.tag="Ok",n.value=t,n},l.Error=function(t){var n=Object.create(h);return n.tag="Error",n.error=t,n},l.fromExecution=function(t){try{return l.Ok(t())}catch(t){return l.Error(t)}},l.all=function(t){for(var n=t.length,r=l.Ok([]),e=0,o=function(){if(e>=n)return{v:r};var o=t[e];r=r.flatMap(function(t){return o.map(function(n){return t.push(n),t})}),e++};;){var i=o();if("object"==typeof i)return i.v}},l.equals=function(t,n,r){return t.tag===n.tag&&("Error"===t.tag&&"Error"===n.tag||r(t.value,n.value))},l.pattern={Ok:function(t){return{tag:"Ok",value:t}},Error:function(t){return{tag:"Error",error:t}}},l.prototype.__boxed_type__="Result";var h=Object.create(null,Object.getOwnPropertyDescriptors(l.prototype));function v(t){var n=this,r={};this.tag="Pending",this.pending=r,r.cancel=t(function(t){if("Pending"===n.tag){var r=n.pending.resolveCallbacks;null==r||r.forEach(function(n){return n(t)}),n.tag="Resolved",n.value=t,n.pending=void 0}})}var g=/*#__PURE__*/function(){function t(t){this.tag=void 0,this.value=void 0,this.pending=void 0,this.tag="Pending",this.pending={}}t.fromPromise=function(n){return t.make(function(t){n.then(function(n){return t(l.Ok(n))},function(n){return t(l.Error(n))})})};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,r=this.pending;r.resolveCallbacks=null!=(n=r.resolveCallbacks)?n:[],r.resolveCallbacks.push(t)}this.isResolved()&&t(this.value)},n.onCancel=function(t){if(this.isPending()){var n,r=this.pending;r.cancelCallbacks=null!=(n=r.cancelCallbacks)?n:[],r.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(n,r){var e=this;void 0===r&&(r=!1);var o=t.make(function(t){if(e.get(function(r){t(n(r))}),r)return function(){e.cancel()}});return this.onCancel(function(){o.cancel()}),o},n.then=function(t){return this.get(t),this},n.flatMap=function(n,r){var e=this;void 0===r&&(r=!1);var o=t.make(function(t){if(e.get(function(r){var e=n(r);e.get(t),e.onCancel(function(){return o.cancel()})}),r)return function(){e.cancel()}});return this.onCancel(function(){o.cancel()}),o},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 l.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 l.Error(t(n))}})},n)},n.flatMapOk=function(n,r){return void 0===r&&(r=!1),this.flatMap(function(r){return r.match({Ok:function(t){return n(t)},Error:function(){return t.value(r)}})},r)},n.flatMapError=function(n,r){return void 0===r&&(r=!1),this.flatMap(function(r){return r.match({Ok:function(){return t.value(r)},Error:function(t){return n(t)}})},r)},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,r){t.get(function(t){t.match({Ok:n,Error:r})})})},t}();g.make=function(t){var n=Object.create(p);return v.call(n,t),n},g.value=function(t){var n=Object.create(p);return v.call(n,function(n){return n(t)}),n},g.all=function(t,n){void 0===n&&(n=!1);for(var r=t.length,e=g.value([]),o=0,i=function(){if(o>=r)return{v:e};var i=t[o];e=e.flatMap(function(t){return i.map(function(n){return t.push(n),t},n)},n),o++};;){var u=i();if("object"==typeof u)return u.v}};var p=Object.create(null,Object.getOwnPropertyDescriptors(g.prototype)),d={make:function(){var t=void 0;return[g.make(function(n){t=n}),t]}},_={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},m=Symbol.for("NOT_COMPUTED"),O={__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__?"Error"===n.tag?{__boxed_type__:"Result",tag:n.tag,error:n.error}:{__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(n){return JSON.parse(n,function(n,r){return null==r?r:"Option"===r.__boxed_type__?"Some"===r.tag?t.Some(r.value):t.None():"Result"===r.__boxed_type__?"Ok"===r.tag?l.Ok(r.value):l.Error(r.error):"AsyncData"===r.__boxed_type__?"NotAsked"===r.tag?u.NotAsked():"Loading"===r.tag?u.Loading():u.Done(r.value):r})}};exports.Array=i,exports.AsyncData=u,exports.Deferred=d,exports.Dict=_,exports.Future=g,exports.Lazy=function(t){var n={contents:m};return{get value(){return n.contents===m&&(n.contents=t()),n.contents}}},exports.Option=t,exports.Result=l,exports.Serializer=O; | ||
//# sourceMappingURL=Boxed.js.map |
@@ -7,12 +7,7 @@ import { Result } from "./Result"; | ||
}; | ||
export declare type Future<Value> = FutureClass<Value> & ({ | ||
tag: "Pending"; | ||
pending: PendingPayload<Value>; | ||
} | { | ||
tag: "Cancelled"; | ||
} | { | ||
tag: "Resolved"; | ||
value: Value; | ||
}); | ||
declare class FutureClass<Value> { | ||
export declare class Future<Value> { | ||
static make: <Value_1>(init: (resolver: (value: Value_1) => void) => (() => void) | void) => Future<Value_1>; | ||
static value: <Value_1>(value: Value_1) => Future<Value_1>; | ||
static fromPromise<Value>(promise: Promise<Value>): Future<Result<Value, unknown>>; | ||
static all: typeof all; | ||
tag: "Pending" | "Cancelled" | "Resolved"; | ||
@@ -54,8 +49,2 @@ value?: Value; | ||
}>; | ||
export declare const Future: { | ||
make: <Value>(init: (resolver: (value: Value) => void) => (() => void) | void) => Future<Value>; | ||
value: <Value_1>(value: Value_1) => Future<Value_1>; | ||
fromPromise<Value_2>(promise: Promise<Value_2>): Future<Result<Value_2, unknown>>; | ||
all: typeof all; | ||
}; | ||
export {}; |
@@ -1,15 +0,60 @@ | ||
export declare type Option<Value> = OptionClass<Value> & ({ | ||
tag: "Some"; | ||
value: Value; | ||
} | { | ||
tag: "None"; | ||
value: undefined; | ||
}); | ||
declare class OptionClass<Value> { | ||
export declare class Option<Value> { | ||
/** | ||
* Create an AsyncData.Some value | ||
*/ | ||
static Some: <Value_1>(value: Value_1) => Option<Value_1>; | ||
/** | ||
* Create an Option.None value | ||
*/ | ||
static None: <Value_1>() => Option<Value_1>; | ||
/** | ||
* Create an Option from a nullable value | ||
*/ | ||
static fromNullable: <NullableValue>(nullable: NullableValue) => Option<NonNullable<NullableValue>>; | ||
/** | ||
* Create an Option from a null | value | ||
*/ | ||
static fromNull: <NullableValue>(nullable: NullableValue) => Option<Exclude<NullableValue, null>>; | ||
/** | ||
* Create an Option from a undefined | value | ||
*/ | ||
static fromUndefined: <NullableValue>(nullable: NullableValue) => Option<Exclude<NullableValue, undefined>>; | ||
/** | ||
* Turns an array of options into an option of array | ||
*/ | ||
static all: <Options extends [] | readonly Option<any>[]>(options: Options) => Option<{ -readonly [P in keyof Options]: Options[P] extends Option<infer V> ? V : never; }>; | ||
static equals: <Value_1>(a: Option<Value_1>, b: Option<Value_1>, equals: (a: Value_1, b: Value_1) => boolean) => boolean; | ||
static pattern: { | ||
Some: <T>(x: T) => { | ||
readonly tag: "Some"; | ||
readonly value: T; | ||
}; | ||
None: { | ||
readonly tag: "None"; | ||
}; | ||
}; | ||
tag: "Some" | "None"; | ||
value: Value | undefined; | ||
constructor(); | ||
/** | ||
* Returns the Option containing the value from the callback | ||
* | ||
* (Option\<A>, A => B) => Option\<B> | ||
*/ | ||
map<ReturnValue>(f: (value: Value) => ReturnValue): Option<ReturnValue>; | ||
/** | ||
* Returns the Option containing the value from the callback | ||
* | ||
* (Option\<A>, A => Option\<B>) => Option\<B> | ||
*/ | ||
flatMap<ReturnValue>(f: (value: Value) => Option<ReturnValue>): Option<ReturnValue>; | ||
/** | ||
* Return the value if present, and the fallback otherwise | ||
* | ||
* (Option\<A>, A) => A | ||
*/ | ||
getWithDefault(defaultValue: Value): Value; | ||
/** | ||
* Explodes the Option given its case | ||
*/ | ||
match<ReturnValue>(config: { | ||
@@ -19,10 +64,25 @@ Some: (value: Value) => ReturnValue; | ||
}): ReturnValue; | ||
/** | ||
* Runs the callback and returns `this` | ||
*/ | ||
tap(this: Option<Value>, func: (option: Option<Value>) => unknown): Option<Value>; | ||
/** | ||
* Converts the Option\<A> to a `A | undefined` | ||
*/ | ||
toUndefined(): Value | undefined; | ||
/** | ||
* Converts the Option\<A> to a `A | null` | ||
*/ | ||
toNull(): Value | null; | ||
isSome(): this is OptionClass<Value> & { | ||
/** | ||
* Typeguard | ||
*/ | ||
isSome(): this is Option<Value> & { | ||
tag: "Some"; | ||
value: Value; | ||
}; | ||
isNone(): this is OptionClass<Value> & { | ||
/** | ||
* Typeguard | ||
*/ | ||
isNone(): this is Option<Value> & { | ||
tag: "None"; | ||
@@ -32,20 +92,1 @@ value: undefined; | ||
} | ||
export declare const Option: { | ||
Some: <Value>(value: Value) => Option<Value>; | ||
None: <Value_1>() => Option<Value_1>; | ||
fromNullable: <NullableValue>(nullable: NullableValue) => Option<NonNullable<NullableValue>>; | ||
fromNull: <NullableValue_1>(nullable: NullableValue_1) => Option<Exclude<NullableValue_1, null>>; | ||
fromUndefined: <NullableValue_2>(nullable: NullableValue_2) => Option<Exclude<NullableValue_2, undefined>>; | ||
all: <Options extends [] | readonly Option<any>[]>(options: Options) => Option<{ -readonly [P in keyof Options]: Options[P] extends Option<infer V> ? V : never; }>; | ||
equals: <Value_2>(a: Option<Value_2>, b: Option<Value_2>, equals: (a: Value_2, b: Value_2) => boolean) => boolean; | ||
pattern: { | ||
Some: <T>(x: T) => { | ||
readonly tag: "Some"; | ||
readonly value: T; | ||
}; | ||
None: { | ||
readonly tag: "None"; | ||
}; | ||
}; | ||
}; | ||
export {}; |
import { Option } from "./Option"; | ||
export declare type Result<Ok, Error> = ResultClass<Ok, Error> & ({ | ||
tag: "Ok"; | ||
value: Ok; | ||
} | { | ||
tag: "Error"; | ||
value: Error; | ||
}); | ||
declare class ResultClass<Ok, Error> { | ||
export declare class Result<Ok, Error> { | ||
/** | ||
* Create an Result.Ok value | ||
*/ | ||
static Ok: <Ok_1, Error_1>(ok: Ok_1) => Result<Ok_1, Error_1>; | ||
/** | ||
* Create an Result.Error value | ||
*/ | ||
static Error: <Ok_1, Error_1>(error: Error_1) => Result<Ok_1, Error_1>; | ||
/** | ||
* Runs the function and resolves a result of its return value, or to an error if thrown | ||
*/ | ||
static fromExecution: <ReturnValue, Error_1 = unknown>(func: () => ReturnValue) => Result<ReturnValue, Error_1>; | ||
/** | ||
* Takes the promise and resolves a result of its value, or to an error if rejected | ||
*/ | ||
static fromPromise<ReturnValue, Error = unknown>(promise: Promise<ReturnValue>): Promise<Result<ReturnValue, Error>>; | ||
/** | ||
* Turns an array of results into an result of array | ||
*/ | ||
static all: <Results extends [] | readonly Result<any, any>[]>(results: Results) => Result<{ -readonly [P in keyof Results]: Results[P] extends Result<infer V, any> ? V : never; }, { -readonly [P_1 in keyof Results]: Results[P_1] extends Result<any, infer E> ? E : never; }[number]>; | ||
static equals: <Value, Error_1>(a: Result<Value, Error_1>, b: Result<Value, Error_1>, equals: (a: Value, b: Value) => boolean) => boolean; | ||
static pattern: { | ||
Ok: <T>(x: T) => { | ||
readonly tag: "Ok"; | ||
readonly value: T; | ||
}; | ||
Error: <T_1>(x: T_1) => { | ||
readonly tag: "Error"; | ||
readonly error: T_1; | ||
}; | ||
}; | ||
tag: "Ok" | "Error"; | ||
value: Ok | Error; | ||
value: Ok | undefined; | ||
error: Error | undefined; | ||
constructor(); | ||
/** | ||
* Returns the Result containing the value from the callback | ||
* | ||
* (Result\<A, E>, A => B) => Result\<B> | ||
*/ | ||
map<ReturnValue>(f: (value: Ok) => ReturnValue): Result<ReturnValue, Error>; | ||
/** | ||
* Returns the Result containing the error returned from the callback | ||
* | ||
* (Result\<A, E>, E => F) => Result\<F> | ||
*/ | ||
mapError<ReturnError>(f: (value: Error) => ReturnError): Result<Ok, ReturnError>; | ||
/** | ||
* Returns the Result containing the value from the callback | ||
* | ||
* (Result\<A, E>, A => Result\<B, F>) => Result\<B, E | F> | ||
*/ | ||
flatMap<ReturnValue, ResultError = Error>(f: (value: Ok) => Result<ReturnValue, ResultError | Error>): Result<ReturnValue, ResultError | Error>; | ||
/** | ||
* Returns the Result containing the value from the callback | ||
* | ||
* (Result\<A, E>, E => Result\<A, F>) => Result\<A | B, F> | ||
*/ | ||
flatMapError<ReturnValue, ResultError>(f: (value: Error) => Result<ReturnValue, ResultError>): Result<Ok | ReturnValue, ResultError>; | ||
/** | ||
* Return the value if present, and the fallback otherwise | ||
* | ||
* (Result\<A, E>, A) => A | ||
*/ | ||
getWithDefault(defaultValue: Ok): Ok; | ||
/** | ||
* Explodes the Result given its case | ||
*/ | ||
match<ReturnValue>(config: { | ||
@@ -22,5 +75,17 @@ Ok: (value: Ok) => ReturnValue; | ||
}): ReturnValue; | ||
/** | ||
* Runs the callback and returns `this` | ||
*/ | ||
tap(this: Result<Ok, Error>, func: (result: Result<Ok, Error>) => unknown): Result<Ok, Error>; | ||
/** | ||
* Runs the callback if ok and returns `this` | ||
*/ | ||
tapOk(this: Result<Ok, Error>, func: (value: Ok) => unknown): Result<Ok, Error>; | ||
/** | ||
* Runs the callback if error and returns `this` | ||
*/ | ||
tapError(this: Result<Ok, Error>, func: (error: Error) => unknown): Result<Ok, Error>; | ||
/** | ||
* Typeguard | ||
*/ | ||
isOk(): this is Result<Ok, Error> & { | ||
@@ -30,26 +95,15 @@ tag: "Ok"; | ||
}; | ||
/** | ||
* Typeguard | ||
*/ | ||
isError(): this is Result<Ok, Error> & { | ||
tag: "Error"; | ||
value: Error; | ||
error: Error; | ||
}; | ||
/** | ||
* Return an option of the value | ||
* | ||
* (Result\<A, E>) => Option\<A> | ||
*/ | ||
toOption(): Option<Ok>; | ||
} | ||
export declare const Result: { | ||
Ok: <Ok, Error_1>(ok: Ok) => Result<Ok, Error_1>; | ||
Error: <Ok_1, Error_2>(error: Error_2) => Result<Ok_1, Error_2>; | ||
fromExecution<ReturnValue, Error_3 = unknown>(func: () => ReturnValue): Result<ReturnValue, Error_3>; | ||
fromPromise<ReturnValue_1, Error_4 = unknown>(promise: Promise<ReturnValue_1>): Promise<Result<ReturnValue_1, Error_4>>; | ||
all: <Results extends [] | readonly Result<any, any>[]>(results: Results) => Result<{ -readonly [P in keyof Results]: Results[P] extends Result<infer V, any> ? V : never; }, { -readonly [P_1 in keyof Results]: Results[P_1] extends Result<any, infer E> ? E : never; }[number]>; | ||
equals: <Value, Error_5>(a: Result<Value, Error_5>, b: Result<Value, Error_5>, equals: (a: Value, b: Value) => boolean) => boolean; | ||
pattern: { | ||
Ok: <T>(x: T) => { | ||
readonly tag: "Ok"; | ||
readonly value: T; | ||
}; | ||
Error: <T_1>(x: T_1) => { | ||
readonly tag: "Error"; | ||
readonly value: T_1; | ||
}; | ||
}; | ||
}; | ||
export {}; |
@@ -0,1 +1,11 @@ | ||
# 0.4.0 | ||
Breaking changes: | ||
- In case of `Error`, `Result` class stores the value in `result.error` (57e254b) | ||
Features: | ||
- Better IDE integration and TypeScript errors (57e254b) | ||
# 0.3.7 | ||
@@ -2,0 +12,0 @@ |
{ | ||
"name": "@swan-io/boxed", | ||
"version": "0.3.7", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -48,3 +48,3 @@ "description": "Utility types for functional TypeScript", | ||
"prettier-plugin-organize-imports": "^2.3.4", | ||
"ts-pattern": "^3.3.5", | ||
"ts-pattern": "^4.0.0", | ||
"typescript": "^4.6.2", | ||
@@ -51,0 +51,0 @@ "vitest": "^0.7.4" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
131511
454
1