@swan-io/boxed
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -108,2 +108,11 @@ import { Option } from "./Option"; | ||
toOption(): Option<Value>; | ||
/** | ||
* Returns the value. Use within `if (asyncData.isDone()) { ... }` | ||
*/ | ||
get(this: AsyncData<Value> & { | ||
value: { | ||
tag: "Done"; | ||
value: Value; | ||
}; | ||
}): Value; | ||
} |
@@ -1,2 +0,2 @@ | ||
var t=/*#__PURE__*/function(){function t(){this.value=void 0,this.value={tag:"None"}}var n=t.prototype;return n.map=function(n){return"Some"===this.value.tag?t.Some(n(this.value.value)):this},n.flatMap=function(t){return"Some"===this.value.tag?t(this.value.value):this},n.getWithDefault=function(t){return"Some"===this.value.tag?this.value.value:t},n.match=function(t){return"Some"===this.value.tag?t.Some(this.value.value):t.None()},n.tap=function(t){return t(this),this},n.toUndefined=function(){return"None"===this.value.tag?void 0:this.value.value},n.toNull=function(){return"None"===this.value.tag?null:this.value.value},n.isSome=function(){return"Some"===this.value.tag},n.isNone=function(){return"None"===this.value.tag},t}();t.Some=function(t){var n=Object.create(e);return n.value={tag:"Some",value:t},n},t.None=function(){return r},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 e=n.length,r=t.Some([]),u=0,a=function(){if(u>=e)return{v:r};var t=n[u];r=r.flatMap(function(n){return t.map(function(t){return n.push(t),n})}),u++};;){var o=a();if("object"==typeof o)return o.v}},t.equals=function(t,n,e){return t.isSome()&&n.isSome()?e(t.value.value,n.value.value):t.value.tag===n.value.tag},t.pattern={Some:function(t){return{value:{tag:"Some",value:t}}},None:{value:{tag:"None"}}},t.prototype.__boxed_type__="Option";var n,e=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),r=((n=Object.create(e)).value={tag:"None"},n),u=function(t,n){return t===n?0:t>n?1:-1},a={__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(n,e){for(var r=-1;++r<n.length;){var u=n[r];if(e(u))return t.Some(u)}return t.None()},getIndexBy:function(n,e){for(var r=-1;++r<n.length;)if(e(n[r]))return t.Some(r);return t.None()},binarySearchBy:function(t,n,e){if(void 0===e&&(e=u),0===t.length)return-1;for(var r=0,a=t.length-1;;){var o=r+(a-r)/2|0;if(o===r||o===a)return a;var i=e(n,t[o]);if(0===i)return o;i>0?r=o:i<0&&(a=o)}}},o=/*#__PURE__*/function(){function n(){this.value=void 0,this.value={tag:"NotAsked"}}var e=n.prototype;return e.map=function(t){return"Done"===this.value.tag?n.Done(t(this.value.value)):this},e.flatMap=function(t){return"Done"===this.value.tag?t(this.value.value):this},e.getWithDefault=function(t){return"Done"===this.value.tag?this.value.value:t},e.match=function(t){return"Done"===this.value.tag?t.Done(this.value.value):"Loading"===this.value.tag?t.Loading():t.NotAsked()},e.tap=function(t){return t(this),this},e.isDone=function(){return"Done"===this.value.tag},e.isLoading=function(){return"Loading"===this.value.tag},e.isNotAsked=function(){return"NotAsked"===this.value.tag},e.toOption=function(){return"Done"===this.value.tag?t.Some(this.value.value):t.None()},n}();o.Done=function(t){var n=Object.create(l);return n.value={tag:"Done",value:t},n},o.Loading=function(){return c},o.NotAsked=function(){return v},o.all=function(t){for(var n=t.length,e=o.Done([]),r=0,u=function(){if(r>=n)return{v:e};var u=t[r];e=e.flatMap(function(t){return u.map(function(n){return t.push(n),t})}),r++};;){var a=u();if("object"==typeof a)return a.v}},o.equals=function(t,n,e){return t.isDone()&&n.isDone()?e(t.value.value,n.value.value):t.value.tag===n.value.tag},o.pattern={Done:function(t){return{value:{tag:"Done",value:t}}},NotAsked:{value:{tag:"NotAsked"}},Loading:{value:{tag:"Loading"}}},o.prototype.__boxed_type__="AsyncData";var i,l=Object.create(null,Object.getOwnPropertyDescriptors(o.prototype)),c=((i=Object.create(l)).value={tag:"Loading"},i),v=function(){var t=Object.create(l);return t.value={tag:"NotAsked"},t}(),f=/*#__PURE__*/function(){function n(){this.value=void 0,this.value={tag:"Error",value:void 0}}n.fromPromise=function(t){try{return Promise.resolve(function(e,r){try{var u=Promise.resolve(t).then(function(t){return n.Ok(t)})}catch(t){return r(t)}return u&&u.then?u.then(void 0,r):u}(0,function(t){return n.Error(t)}))}catch(t){return Promise.reject(t)}};var e=n.prototype;return e.map=function(t){return"Ok"===this.value.tag?n.Ok(t(this.value.value)):this},e.mapError=function(t){return"Ok"===this.value.tag?this:n.Error(t(this.value.value))},e.flatMap=function(t){return"Ok"===this.value.tag?t(this.value.value):this},e.flatMapError=function(t){return"Ok"===this.value.tag?this:t(this.value.value)},e.getWithDefault=function(t){return"Ok"===this.value.tag?this.value.value:t},e.match=function(t){return"Ok"===this.value.tag?t.Ok(this.value.value):t.Error(this.value.value)},e.tap=function(t){return t(this),this},e.tapOk=function(t){return this.isOk()&&t(this.value.value),this},e.tapError=function(t){return this.isError()&&t(this.value.value),this},e.isOk=function(){return"Ok"===this.value.tag},e.isError=function(){return"Error"===this.value.tag},e.toOption=function(){return"Ok"===this.value.tag?t.Some(this.value.value):t.None()},n}();f.Ok=function(t){var n=Object.create(s);return n.value={tag:"Ok",value:t},n},f.Error=function(t){var n=Object.create(s);return n.value={tag:"Error",value:t},n},f.fromExecution=function(t){try{return f.Ok(t())}catch(t){return f.Error(t)}},f.all=function(t){for(var n=t.length,e=f.Ok([]),r=0,u=function(){if(r>=n)return{v:e};var u=t[r];e=e.flatMap(function(t){return u.map(function(n){return t.push(n),t})}),r++};;){var a=u();if("object"==typeof a)return a.v}},f.equals=function(t,n,e){return t.value.tag===n.value.tag&&(!(!t.isError()||!n.isError())||e(t.value.value,n.value.value))},f.pattern={Ok:function(t){return{value:{tag:"Ok",value:t}}},Error:function(t){return{value:{tag:"Error",value:t}}}},f.prototype.__boxed_type__="Result";var s=Object.create(null,Object.getOwnPropertyDescriptors(f.prototype));function h(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 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(f.Ok(n))},function(n){return t(f.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,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(n,e){var r=this;void 0===e&&(e=!1);var u=t.make(function(t){if(r.get(function(e){t(n(e))}),e)return function(){r.cancel()}});return this.onCancel(function(){u.cancel()}),u},n.then=function(t){return this.get(t),this},n.flatMap=function(n,e){var r=this;void 0===e&&(e=!1);var u=t.make(function(t){if(r.get(function(e){var r=n(e);r.get(t),r.onCancel(function(){return u.cancel()})}),e)return function(){r.cancel()}});return this.onCancel(function(){u.cancel()}),u},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 f.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 f.Error(t(n))}})},n)},n.flatMapOk=function(n,e){return void 0===e&&(e=!1),this.flatMap(function(e){return e.match({Ok:function(t){return n(t)},Error:function(){return t.value(e)}})},e)},n.flatMapError=function(n,e){return void 0===e&&(e=!1),this.flatMap(function(e){return e.match({Ok:function(){return t.value(e)},Error:function(t){return n(t)}})},e)},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}();g.make=function(t){var n=Object.create(p);return h.call(n,t),n},g.value=function(t){var n=Object.create(p);return h.call(n,function(n){return n(t)}),n},g.all=function(t,n){void 0===n&&(n=!1);for(var e=t.length,r=g.value([]),u=0,a=function(){if(u>=e)return{v:r};var a=t[u];r=r.flatMap(function(t){return a.map(function(n){return t.push(n),t},n)},n),u++};;){var o=a();if("object"==typeof o)return o.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]}},m={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},_=Symbol.for("NOT_COMPUTED"),O=function(t){var n={contents:_};return{get value(){return n.contents===_&&(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.value.tag,value:n.value.value}:"Result"===n.__boxed_type__?{__boxed_type__:"Result",tag:n.value.tag,value:n.value.value}:"AsyncData"===n.__boxed_type__?{__boxed_type__:"AsyncData",tag:n.value.tag,value:n.value.value}:n},n)},decode:function(n){return JSON.parse(n,function(n,e){return null==e?e:"Option"===e.__boxed_type__?"Some"===e.tag?t.Some(e.value):t.None():"Result"===e.__boxed_type__?"Ok"===e.tag?f.Ok(e.value):f.Error(e.value):"AsyncData"===e.__boxed_type__?"NotAsked"===e.tag?o.NotAsked():"Loading"===e.tag?o.Loading():o.Done(e.value):e})}};export{a as Array,o as AsyncData,d as Deferred,m as Dict,g as Future,O as Lazy,t as Option,f as Result,k as Serializer}; | ||
var t=/*#__PURE__*/function(){function t(){this.value=void 0,this.value={tag:"None"}}var n=t.prototype;return n.map=function(n){return"Some"===this.value.tag?t.Some(n(this.value.value)):this},n.flatMap=function(t){return"Some"===this.value.tag?t(this.value.value):this},n.getWithDefault=function(t){return"Some"===this.value.tag?this.value.value:t},n.match=function(t){return"Some"===this.value.tag?t.Some(this.value.value):t.None()},n.tap=function(t){return t(this),this},n.toUndefined=function(){return"None"===this.value.tag?void 0:this.value.value},n.toNull=function(){return"None"===this.value.tag?null:this.value.value},n.isSome=function(){return"Some"===this.value.tag},n.isNone=function(){return"None"===this.value.tag},n.get=function(){return this.value.value},t}();t.Some=function(t){var n=Object.create(e);return n.value={tag:"Some",value:t},n},t.None=function(){return r},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 e=n.length,r=t.Some([]),u=0,a=function(){if(u>=e)return{v:r};var t=n[u];r=r.flatMap(function(n){return t.map(function(t){return n.push(t),n})}),u++};;){var o=a();if("object"==typeof o)return o.v}},t.equals=function(t,n,e){return t.isSome()&&n.isSome()?e(t.value.value,n.value.value):t.value.tag===n.value.tag},t.pattern={Some:function(t){return{value:{tag:"Some",value:t}}},None:{value:{tag:"None"}}},t.prototype.__boxed_type__="Option";var n,e=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),r=((n=Object.create(e)).value={tag:"None"},n),u=function(t,n){return t===n?0:t>n?1:-1},a={__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(n,e){for(var r=-1;++r<n.length;){var u=n[r];if(e(u))return t.Some(u)}return t.None()},getIndexBy:function(n,e){for(var r=-1;++r<n.length;)if(e(n[r]))return t.Some(r);return t.None()},binarySearchBy:function(t,n,e){if(void 0===e&&(e=u),0===t.length)return-1;for(var r=0,a=t.length-1;;){var o=r+(a-r)/2|0;if(o===r||o===a)return a;var i=e(n,t[o]);if(0===i)return o;i>0?r=o:i<0&&(a=o)}}},o=/*#__PURE__*/function(){function n(){this.value=void 0,this.value={tag:"NotAsked"}}var e=n.prototype;return e.map=function(t){return"Done"===this.value.tag?n.Done(t(this.value.value)):this},e.flatMap=function(t){return"Done"===this.value.tag?t(this.value.value):this},e.getWithDefault=function(t){return"Done"===this.value.tag?this.value.value:t},e.match=function(t){return"Done"===this.value.tag?t.Done(this.value.value):"Loading"===this.value.tag?t.Loading():t.NotAsked()},e.tap=function(t){return t(this),this},e.isDone=function(){return"Done"===this.value.tag},e.isLoading=function(){return"Loading"===this.value.tag},e.isNotAsked=function(){return"NotAsked"===this.value.tag},e.toOption=function(){return"Done"===this.value.tag?t.Some(this.value.value):t.None()},e.get=function(){return this.value.value},n}();o.Done=function(t){var n=Object.create(l);return n.value={tag:"Done",value:t},n},o.Loading=function(){return c},o.NotAsked=function(){return v},o.all=function(t){for(var n=t.length,e=o.Done([]),r=0,u=function(){if(r>=n)return{v:e};var u=t[r];e=e.flatMap(function(t){return u.map(function(n){return t.push(n),t})}),r++};;){var a=u();if("object"==typeof a)return a.v}},o.equals=function(t,n,e){return t.isDone()&&n.isDone()?e(t.value.value,n.value.value):t.value.tag===n.value.tag},o.pattern={Done:function(t){return{value:{tag:"Done",value:t}}},NotAsked:{value:{tag:"NotAsked"}},Loading:{value:{tag:"Loading"}}},o.prototype.__boxed_type__="AsyncData";var i,l=Object.create(null,Object.getOwnPropertyDescriptors(o.prototype)),c=((i=Object.create(l)).value={tag:"Loading"},i),v=function(){var t=Object.create(l);return t.value={tag:"NotAsked"},t}(),f=/*#__PURE__*/function(){function n(){this.value=void 0,this.value={tag:"Error",value:void 0}}n.fromPromise=function(t){try{return Promise.resolve(function(e,r){try{var u=Promise.resolve(t).then(function(t){return n.Ok(t)})}catch(t){return r(t)}return u&&u.then?u.then(void 0,r):u}(0,function(t){return n.Error(t)}))}catch(t){return Promise.reject(t)}};var e=n.prototype;return e.map=function(t){return"Ok"===this.value.tag?n.Ok(t(this.value.value)):this},e.mapError=function(t){return"Ok"===this.value.tag?this:n.Error(t(this.value.value))},e.flatMap=function(t){return"Ok"===this.value.tag?t(this.value.value):this},e.flatMapError=function(t){return"Ok"===this.value.tag?this:t(this.value.value)},e.getWithDefault=function(t){return"Ok"===this.value.tag?this.value.value:t},e.match=function(t){return"Ok"===this.value.tag?t.Ok(this.value.value):t.Error(this.value.value)},e.tap=function(t){return t(this),this},e.tapOk=function(t){return this.isOk()&&t(this.value.value),this},e.tapError=function(t){return this.isError()&&t(this.value.value),this},e.isOk=function(){return"Ok"===this.value.tag},e.isError=function(){return"Error"===this.value.tag},e.toOption=function(){return"Ok"===this.value.tag?t.Some(this.value.value):t.None()},e.get=function(){return this.value.value},e.getError=function(){return this.value.value},n}();f.Ok=function(t){var n=Object.create(s);return n.value={tag:"Ok",value:t},n},f.Error=function(t){var n=Object.create(s);return n.value={tag:"Error",value:t},n},f.fromExecution=function(t){try{return f.Ok(t())}catch(t){return f.Error(t)}},f.all=function(t){for(var n=t.length,e=f.Ok([]),r=0,u=function(){if(r>=n)return{v:e};var u=t[r];e=e.flatMap(function(t){return u.map(function(n){return t.push(n),t})}),r++};;){var a=u();if("object"==typeof a)return a.v}},f.equals=function(t,n,e){return t.value.tag===n.value.tag&&(!(!t.isError()||!n.isError())||e(t.value.value,n.value.value))},f.pattern={Ok:function(t){return{value:{tag:"Ok",value:t}}},Error:function(t){return{value:{tag:"Error",value:t}}}},f.prototype.__boxed_type__="Result";var s=Object.create(null,Object.getOwnPropertyDescriptors(f.prototype));function h(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 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(f.Ok(n))},function(n){return t(f.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,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(n,e){var r=this;void 0===e&&(e=!1);var u=t.make(function(t){if(r.get(function(e){t(n(e))}),e)return function(){r.cancel()}});return this.onCancel(function(){u.cancel()}),u},n.then=function(t){return this.get(t),this},n.flatMap=function(n,e){var r=this;void 0===e&&(e=!1);var u=t.make(function(t){if(r.get(function(e){var r=n(e);r.get(t),r.onCancel(function(){return u.cancel()})}),e)return function(){r.cancel()}});return this.onCancel(function(){u.cancel()}),u},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 f.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 f.Error(t(n))}})},n)},n.flatMapOk=function(n,e){return void 0===e&&(e=!1),this.flatMap(function(e){return e.match({Ok:function(t){return n(t)},Error:function(){return t.value(e)}})},e)},n.flatMapError=function(n,e){return void 0===e&&(e=!1),this.flatMap(function(e){return e.match({Ok:function(){return t.value(e)},Error:function(t){return n(t)}})},e)},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}();g.make=function(t){var n=Object.create(p);return h.call(n,t),n},g.value=function(t){var n=Object.create(p);return h.call(n,function(n){return n(t)}),n},g.all=function(t,n){void 0===n&&(n=!1);for(var e=t.length,r=g.value([]),u=0,a=function(){if(u>=e)return{v:r};var a=t[u];r=r.flatMap(function(t){return a.map(function(n){return t.push(n),t},n)},n),u++};;){var o=a();if("object"==typeof o)return o.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]}},m={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},_=Symbol.for("NOT_COMPUTED"),O=function(t){var n={contents:_};return{get value(){return n.contents===_&&(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.value.tag,value:n.value.value}:"Result"===n.__boxed_type__?{__boxed_type__:"Result",tag:n.value.tag,value:n.value.value}:"AsyncData"===n.__boxed_type__?{__boxed_type__:"AsyncData",tag:n.value.tag,value:n.value.value}:n},n)},decode:function(n){return JSON.parse(n,function(n,e){return null==e?e:"Option"===e.__boxed_type__?"Some"===e.tag?t.Some(e.value):t.None():"Result"===e.__boxed_type__?"Ok"===e.tag?f.Ok(e.value):f.Error(e.value):"AsyncData"===e.__boxed_type__?"NotAsked"===e.tag?o.NotAsked():"Loading"===e.tag?o.Loading():o.Done(e.value):e})}};export{a as Array,o as AsyncData,d as Deferred,m as Dict,g as Future,O as Lazy,t as Option,f as Result,k as Serializer}; | ||
//# sourceMappingURL=Boxed.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var t=/*#__PURE__*/function(){function t(){this.value=void 0,this.value={tag:"None"}}var n=t.prototype;return n.map=function(n){return"Some"===this.value.tag?t.Some(n(this.value.value)):this},n.flatMap=function(t){return"Some"===this.value.tag?t(this.value.value):this},n.getWithDefault=function(t){return"Some"===this.value.tag?this.value.value:t},n.match=function(t){return"Some"===this.value.tag?t.Some(this.value.value):t.None()},n.tap=function(t){return t(this),this},n.toUndefined=function(){return"None"===this.value.tag?void 0:this.value.value},n.toNull=function(){return"None"===this.value.tag?null:this.value.value},n.isSome=function(){return"Some"===this.value.tag},n.isNone=function(){return"None"===this.value.tag},t}();t.Some=function(t){var n=Object.create(e);return n.value={tag:"Some",value:t},n},t.None=function(){return r},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 e=n.length,r=t.Some([]),u=0,a=function(){if(u>=e)return{v:r};var t=n[u];r=r.flatMap(function(n){return t.map(function(t){return n.push(t),n})}),u++};;){var o=a();if("object"==typeof o)return o.v}},t.equals=function(t,n,e){return t.isSome()&&n.isSome()?e(t.value.value,n.value.value):t.value.tag===n.value.tag},t.pattern={Some:function(t){return{value:{tag:"Some",value:t}}},None:{value:{tag:"None"}}},t.prototype.__boxed_type__="Option";var n,e=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),r=((n=Object.create(e)).value={tag:"None"},n),u=function(t,n){return t===n?0:t>n?1:-1},a={__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(n,e){for(var r=-1;++r<n.length;){var u=n[r];if(e(u))return t.Some(u)}return t.None()},getIndexBy:function(n,e){for(var r=-1;++r<n.length;)if(e(n[r]))return t.Some(r);return t.None()},binarySearchBy:function(t,n,e){if(void 0===e&&(e=u),0===t.length)return-1;for(var r=0,a=t.length-1;;){var o=r+(a-r)/2|0;if(o===r||o===a)return a;var i=e(n,t[o]);if(0===i)return o;i>0?r=o:i<0&&(a=o)}}},o=/*#__PURE__*/function(){function n(){this.value=void 0,this.value={tag:"NotAsked"}}var e=n.prototype;return e.map=function(t){return"Done"===this.value.tag?n.Done(t(this.value.value)):this},e.flatMap=function(t){return"Done"===this.value.tag?t(this.value.value):this},e.getWithDefault=function(t){return"Done"===this.value.tag?this.value.value:t},e.match=function(t){return"Done"===this.value.tag?t.Done(this.value.value):"Loading"===this.value.tag?t.Loading():t.NotAsked()},e.tap=function(t){return t(this),this},e.isDone=function(){return"Done"===this.value.tag},e.isLoading=function(){return"Loading"===this.value.tag},e.isNotAsked=function(){return"NotAsked"===this.value.tag},e.toOption=function(){return"Done"===this.value.tag?t.Some(this.value.value):t.None()},n}();o.Done=function(t){var n=Object.create(l);return n.value={tag:"Done",value:t},n},o.Loading=function(){return c},o.NotAsked=function(){return v},o.all=function(t){for(var n=t.length,e=o.Done([]),r=0,u=function(){if(r>=n)return{v:e};var u=t[r];e=e.flatMap(function(t){return u.map(function(n){return t.push(n),t})}),r++};;){var a=u();if("object"==typeof a)return a.v}},o.equals=function(t,n,e){return t.isDone()&&n.isDone()?e(t.value.value,n.value.value):t.value.tag===n.value.tag},o.pattern={Done:function(t){return{value:{tag:"Done",value:t}}},NotAsked:{value:{tag:"NotAsked"}},Loading:{value:{tag:"Loading"}}},o.prototype.__boxed_type__="AsyncData";var i,l=Object.create(null,Object.getOwnPropertyDescriptors(o.prototype)),c=((i=Object.create(l)).value={tag:"Loading"},i),v=function(){var t=Object.create(l);return t.value={tag:"NotAsked"},t}(),s=/*#__PURE__*/function(){function n(){this.value=void 0,this.value={tag:"Error",value:void 0}}n.fromPromise=function(t){try{return Promise.resolve(function(e,r){try{var u=Promise.resolve(t).then(function(t){return n.Ok(t)})}catch(t){return r(t)}return u&&u.then?u.then(void 0,r):u}(0,function(t){return n.Error(t)}))}catch(t){return Promise.reject(t)}};var e=n.prototype;return e.map=function(t){return"Ok"===this.value.tag?n.Ok(t(this.value.value)):this},e.mapError=function(t){return"Ok"===this.value.tag?this:n.Error(t(this.value.value))},e.flatMap=function(t){return"Ok"===this.value.tag?t(this.value.value):this},e.flatMapError=function(t){return"Ok"===this.value.tag?this:t(this.value.value)},e.getWithDefault=function(t){return"Ok"===this.value.tag?this.value.value:t},e.match=function(t){return"Ok"===this.value.tag?t.Ok(this.value.value):t.Error(this.value.value)},e.tap=function(t){return t(this),this},e.tapOk=function(t){return this.isOk()&&t(this.value.value),this},e.tapError=function(t){return this.isError()&&t(this.value.value),this},e.isOk=function(){return"Ok"===this.value.tag},e.isError=function(){return"Error"===this.value.tag},e.toOption=function(){return"Ok"===this.value.tag?t.Some(this.value.value):t.None()},n}();s.Ok=function(t){var n=Object.create(f);return n.value={tag:"Ok",value:t},n},s.Error=function(t){var n=Object.create(f);return n.value={tag:"Error",value:t},n},s.fromExecution=function(t){try{return s.Ok(t())}catch(t){return s.Error(t)}},s.all=function(t){for(var n=t.length,e=s.Ok([]),r=0,u=function(){if(r>=n)return{v:e};var u=t[r];e=e.flatMap(function(t){return u.map(function(n){return t.push(n),t})}),r++};;){var a=u();if("object"==typeof a)return a.v}},s.equals=function(t,n,e){return t.value.tag===n.value.tag&&(!(!t.isError()||!n.isError())||e(t.value.value,n.value.value))},s.pattern={Ok:function(t){return{value:{tag:"Ok",value:t}}},Error:function(t){return{value:{tag:"Error",value:t}}}},s.prototype.__boxed_type__="Result";var f=Object.create(null,Object.getOwnPropertyDescriptors(s.prototype));function h(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 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(s.Ok(n))},function(n){return t(s.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,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(n,e){var r=this;void 0===e&&(e=!1);var u=t.make(function(t){if(r.get(function(e){t(n(e))}),e)return function(){r.cancel()}});return this.onCancel(function(){u.cancel()}),u},n.then=function(t){return this.get(t),this},n.flatMap=function(n,e){var r=this;void 0===e&&(e=!1);var u=t.make(function(t){if(r.get(function(e){var r=n(e);r.get(t),r.onCancel(function(){return u.cancel()})}),e)return function(){r.cancel()}});return this.onCancel(function(){u.cancel()}),u},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 s.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 s.Error(t(n))}})},n)},n.flatMapOk=function(n,e){return void 0===e&&(e=!1),this.flatMap(function(e){return e.match({Ok:function(t){return n(t)},Error:function(){return t.value(e)}})},e)},n.flatMapError=function(n,e){return void 0===e&&(e=!1),this.flatMap(function(e){return e.match({Ok:function(){return t.value(e)},Error:function(t){return n(t)}})},e)},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}();g.make=function(t){var n=Object.create(p);return h.call(n,t),n},g.value=function(t){var n=Object.create(p);return h.call(n,function(n){return n(t)}),n},g.all=function(t,n){void 0===n&&(n=!1);for(var e=t.length,r=g.value([]),u=0,a=function(){if(u>=e)return{v:r};var a=t[u];r=r.flatMap(function(t){return a.map(function(n){return t.push(n),t},n)},n),u++};;){var o=a();if("object"==typeof o)return o.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]}},m={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},_=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.value.tag,value:n.value.value}:"Result"===n.__boxed_type__?{__boxed_type__:"Result",tag:n.value.tag,value:n.value.value}:"AsyncData"===n.__boxed_type__?{__boxed_type__:"AsyncData",tag:n.value.tag,value:n.value.value}:n},n)},decode:function(n){return JSON.parse(n,function(n,e){return null==e?e:"Option"===e.__boxed_type__?"Some"===e.tag?t.Some(e.value):t.None():"Result"===e.__boxed_type__?"Ok"===e.tag?s.Ok(e.value):s.Error(e.value):"AsyncData"===e.__boxed_type__?"NotAsked"===e.tag?o.NotAsked():"Loading"===e.tag?o.Loading():o.Done(e.value):e})}};exports.Array=a,exports.AsyncData=o,exports.Deferred=d,exports.Dict=m,exports.Future=g,exports.Lazy=function(t){var n={contents:_};return{get value(){return n.contents===_&&(n.contents=t()),n.contents}}},exports.Option=t,exports.Result=s,exports.Serializer=O; | ||
var t=/*#__PURE__*/function(){function t(){this.value=void 0,this.value={tag:"None"}}var n=t.prototype;return n.map=function(n){return"Some"===this.value.tag?t.Some(n(this.value.value)):this},n.flatMap=function(t){return"Some"===this.value.tag?t(this.value.value):this},n.getWithDefault=function(t){return"Some"===this.value.tag?this.value.value:t},n.match=function(t){return"Some"===this.value.tag?t.Some(this.value.value):t.None()},n.tap=function(t){return t(this),this},n.toUndefined=function(){return"None"===this.value.tag?void 0:this.value.value},n.toNull=function(){return"None"===this.value.tag?null:this.value.value},n.isSome=function(){return"Some"===this.value.tag},n.isNone=function(){return"None"===this.value.tag},n.get=function(){return this.value.value},t}();t.Some=function(t){var n=Object.create(e);return n.value={tag:"Some",value:t},n},t.None=function(){return r},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 e=n.length,r=t.Some([]),u=0,a=function(){if(u>=e)return{v:r};var t=n[u];r=r.flatMap(function(n){return t.map(function(t){return n.push(t),n})}),u++};;){var o=a();if("object"==typeof o)return o.v}},t.equals=function(t,n,e){return t.isSome()&&n.isSome()?e(t.value.value,n.value.value):t.value.tag===n.value.tag},t.pattern={Some:function(t){return{value:{tag:"Some",value:t}}},None:{value:{tag:"None"}}},t.prototype.__boxed_type__="Option";var n,e=Object.create(null,Object.getOwnPropertyDescriptors(t.prototype)),r=((n=Object.create(e)).value={tag:"None"},n),u=function(t,n){return t===n?0:t>n?1:-1},a={__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(n,e){for(var r=-1;++r<n.length;){var u=n[r];if(e(u))return t.Some(u)}return t.None()},getIndexBy:function(n,e){for(var r=-1;++r<n.length;)if(e(n[r]))return t.Some(r);return t.None()},binarySearchBy:function(t,n,e){if(void 0===e&&(e=u),0===t.length)return-1;for(var r=0,a=t.length-1;;){var o=r+(a-r)/2|0;if(o===r||o===a)return a;var i=e(n,t[o]);if(0===i)return o;i>0?r=o:i<0&&(a=o)}}},o=/*#__PURE__*/function(){function n(){this.value=void 0,this.value={tag:"NotAsked"}}var e=n.prototype;return e.map=function(t){return"Done"===this.value.tag?n.Done(t(this.value.value)):this},e.flatMap=function(t){return"Done"===this.value.tag?t(this.value.value):this},e.getWithDefault=function(t){return"Done"===this.value.tag?this.value.value:t},e.match=function(t){return"Done"===this.value.tag?t.Done(this.value.value):"Loading"===this.value.tag?t.Loading():t.NotAsked()},e.tap=function(t){return t(this),this},e.isDone=function(){return"Done"===this.value.tag},e.isLoading=function(){return"Loading"===this.value.tag},e.isNotAsked=function(){return"NotAsked"===this.value.tag},e.toOption=function(){return"Done"===this.value.tag?t.Some(this.value.value):t.None()},e.get=function(){return this.value.value},n}();o.Done=function(t){var n=Object.create(l);return n.value={tag:"Done",value:t},n},o.Loading=function(){return c},o.NotAsked=function(){return v},o.all=function(t){for(var n=t.length,e=o.Done([]),r=0,u=function(){if(r>=n)return{v:e};var u=t[r];e=e.flatMap(function(t){return u.map(function(n){return t.push(n),t})}),r++};;){var a=u();if("object"==typeof a)return a.v}},o.equals=function(t,n,e){return t.isDone()&&n.isDone()?e(t.value.value,n.value.value):t.value.tag===n.value.tag},o.pattern={Done:function(t){return{value:{tag:"Done",value:t}}},NotAsked:{value:{tag:"NotAsked"}},Loading:{value:{tag:"Loading"}}},o.prototype.__boxed_type__="AsyncData";var i,l=Object.create(null,Object.getOwnPropertyDescriptors(o.prototype)),c=((i=Object.create(l)).value={tag:"Loading"},i),v=function(){var t=Object.create(l);return t.value={tag:"NotAsked"},t}(),s=/*#__PURE__*/function(){function n(){this.value=void 0,this.value={tag:"Error",value:void 0}}n.fromPromise=function(t){try{return Promise.resolve(function(e,r){try{var u=Promise.resolve(t).then(function(t){return n.Ok(t)})}catch(t){return r(t)}return u&&u.then?u.then(void 0,r):u}(0,function(t){return n.Error(t)}))}catch(t){return Promise.reject(t)}};var e=n.prototype;return e.map=function(t){return"Ok"===this.value.tag?n.Ok(t(this.value.value)):this},e.mapError=function(t){return"Ok"===this.value.tag?this:n.Error(t(this.value.value))},e.flatMap=function(t){return"Ok"===this.value.tag?t(this.value.value):this},e.flatMapError=function(t){return"Ok"===this.value.tag?this:t(this.value.value)},e.getWithDefault=function(t){return"Ok"===this.value.tag?this.value.value:t},e.match=function(t){return"Ok"===this.value.tag?t.Ok(this.value.value):t.Error(this.value.value)},e.tap=function(t){return t(this),this},e.tapOk=function(t){return this.isOk()&&t(this.value.value),this},e.tapError=function(t){return this.isError()&&t(this.value.value),this},e.isOk=function(){return"Ok"===this.value.tag},e.isError=function(){return"Error"===this.value.tag},e.toOption=function(){return"Ok"===this.value.tag?t.Some(this.value.value):t.None()},e.get=function(){return this.value.value},e.getError=function(){return this.value.value},n}();s.Ok=function(t){var n=Object.create(f);return n.value={tag:"Ok",value:t},n},s.Error=function(t){var n=Object.create(f);return n.value={tag:"Error",value:t},n},s.fromExecution=function(t){try{return s.Ok(t())}catch(t){return s.Error(t)}},s.all=function(t){for(var n=t.length,e=s.Ok([]),r=0,u=function(){if(r>=n)return{v:e};var u=t[r];e=e.flatMap(function(t){return u.map(function(n){return t.push(n),t})}),r++};;){var a=u();if("object"==typeof a)return a.v}},s.equals=function(t,n,e){return t.value.tag===n.value.tag&&(!(!t.isError()||!n.isError())||e(t.value.value,n.value.value))},s.pattern={Ok:function(t){return{value:{tag:"Ok",value:t}}},Error:function(t){return{value:{tag:"Error",value:t}}}},s.prototype.__boxed_type__="Result";var f=Object.create(null,Object.getOwnPropertyDescriptors(s.prototype));function h(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 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(s.Ok(n))},function(n){return t(s.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,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(n,e){var r=this;void 0===e&&(e=!1);var u=t.make(function(t){if(r.get(function(e){t(n(e))}),e)return function(){r.cancel()}});return this.onCancel(function(){u.cancel()}),u},n.then=function(t){return this.get(t),this},n.flatMap=function(n,e){var r=this;void 0===e&&(e=!1);var u=t.make(function(t){if(r.get(function(e){var r=n(e);r.get(t),r.onCancel(function(){return u.cancel()})}),e)return function(){r.cancel()}});return this.onCancel(function(){u.cancel()}),u},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 s.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 s.Error(t(n))}})},n)},n.flatMapOk=function(n,e){return void 0===e&&(e=!1),this.flatMap(function(e){return e.match({Ok:function(t){return n(t)},Error:function(){return t.value(e)}})},e)},n.flatMapError=function(n,e){return void 0===e&&(e=!1),this.flatMap(function(e){return e.match({Ok:function(){return t.value(e)},Error:function(t){return n(t)}})},e)},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}();g.make=function(t){var n=Object.create(p);return h.call(n,t),n},g.value=function(t){var n=Object.create(p);return h.call(n,function(n){return n(t)}),n},g.all=function(t,n){void 0===n&&(n=!1);for(var e=t.length,r=g.value([]),u=0,a=function(){if(u>=e)return{v:r};var a=t[u];r=r.flatMap(function(t){return a.map(function(n){return t.push(n),t},n)},n),u++};;){var o=a();if("object"==typeof o)return o.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]}},m={__proto__:null,entries:function(t){return Object.entries(t)},keys:function(t){return Object.keys(t)},values:function(t){return Object.values(t)}},_=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.value.tag,value:n.value.value}:"Result"===n.__boxed_type__?{__boxed_type__:"Result",tag:n.value.tag,value:n.value.value}:"AsyncData"===n.__boxed_type__?{__boxed_type__:"AsyncData",tag:n.value.tag,value:n.value.value}:n},n)},decode:function(n){return JSON.parse(n,function(n,e){return null==e?e:"Option"===e.__boxed_type__?"Some"===e.tag?t.Some(e.value):t.None():"Result"===e.__boxed_type__?"Ok"===e.tag?s.Ok(e.value):s.Error(e.value):"AsyncData"===e.__boxed_type__?"NotAsked"===e.tag?o.NotAsked():"Loading"===e.tag?o.Loading():o.Done(e.value):e})}};exports.Array=a,exports.AsyncData=o,exports.Deferred=d,exports.Dict=m,exports.Future=g,exports.Lazy=function(t){var n={contents:_};return{get value(){return n.contents===_&&(n.contents=t()),n.contents}}},exports.Option=t,exports.Result=s,exports.Serializer=O; | ||
//# sourceMappingURL=Boxed.js.map |
@@ -101,2 +101,11 @@ export declare class Option<Value> { | ||
}; | ||
/** | ||
* Returns the value. Use within `if (option.isSome()) { ... }` | ||
*/ | ||
get(this: Option<Value> & { | ||
value: { | ||
tag: "Some"; | ||
value: Value; | ||
}; | ||
}): Value; | ||
} |
@@ -119,2 +119,20 @@ import { Option } from "./Option"; | ||
toOption(): Option<Ok>; | ||
/** | ||
* Returns the ok value. Use within `if (result.isOk()) { ... }` | ||
*/ | ||
get(this: Result<Ok, Error> & { | ||
value: { | ||
tag: "Ok"; | ||
value: Ok; | ||
}; | ||
}): Ok; | ||
/** | ||
* Returns the error value. Use within `if (result.isError()) { ... }` | ||
*/ | ||
getError(this: Result<Ok, Error> & { | ||
value: { | ||
tag: "Error"; | ||
value: Error; | ||
}; | ||
}): Error; | ||
} |
@@ -0,1 +1,7 @@ | ||
# 0.5.2 | ||
Features: | ||
- Add convenience `get` methods (23592b0) | ||
# 0.5.1 | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "@swan-io/boxed", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"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
143627
606