@swan-io/boxed
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -83,2 +83,3 @@ import { Option, Result } from "./OptionResult"; | ||
getWithDefault(this: AsyncData<A>, defaultValue: A): A; | ||
getOr(this: AsyncData<A>, defaultValue: A): A; | ||
match<B>(this: AsyncData<A>, config: { | ||
@@ -85,0 +86,0 @@ Done: (value: A) => B; |
@@ -1,2 +0,2 @@ | ||
var t=function(t){return Object.keys(t)},n=function(t){return Object.values(t)},r=Object.prototype.hasOwnProperty,e={__proto__:null,fromEntries:Object.fromEntries,entries:function(t){return Object.entries(t)},keys:t,values:n,fromOptional:function(t){var n={};for(var e in t)if(r.call(t,e)){var o=t[e];if(void 0===o)continue;o.isSome()&&(n[e]=o.get())}return n}},o=Symbol.for("__boxed_type__"),u=function(t,n){for(var r=Math.min(t.length,n.length),e=Array(r),o=-1;++o<r;)e[o]=[t[o],n[o]];return e},i=/*#__PURE__*/function(){function t(){}var n=t.prototype;return n.map=function(t){return this===f?this:s.Some(t(this.value))},n.flatMap=function(t){return this===f?this:t(this.value)},n.filter=function(t){return this===f||t(this.value)?this:f},n.get=function(){return this.value},n.getWithDefault=function(t){return this===f?t:this.value},n.match=function(t){return this===f?t.None():t.Some(this.value)},n.tap=function(t){return t(this),this},n.toUndefined=function(){if(this!==f)return this.value},n.toNull=function(){return this===f?null:this.value},n.toResult=function(t){return this.match({Some:function(t){return v.Ok(t)},None:function(){return v.Error(t)}})},n.isSome=function(){return this!==f},n.isNone=function(){return this===f},n.toJSON=function(){return this.match({None:function(){var t;return(t={})[o]="Option",t.tag="None",t},Some:function(t){var n;return(n={})[o]="Option",n.tag="Some",n.value=t,n}})},t}();i.P={Some:function(t){return{tag:"Some",value:t}},None:{tag:"None"}},i.Some=function(t){var n=Object.create(c);return n.tag="Some",n.value=t,n},i.None=function(){return f},i.isOption=function(t){return null!=t&&"Option"===t.__boxed_type__},i.fromNullable=function(t){return null==t?f:s.Some(t)},i.fromNull=function(t){return null===t?f:s.Some(t)},i.fromUndefined=function(t){return void 0===t?f:s.Some(t)},i.all=function(t){for(var n,r=t.length,e=s.Some([]),o=0,u=function(){if(o>=r)return{v:e};var n=t[o];null!=n&&(e=e.flatMap(function(t){return n.map(function(n){return t.push(n),t})})),o++};;)if(n=u())return n.v},i.allFromDict=function(r){var e=t(r);return s.all(n(r)).map(function(t){return Object.fromEntries(u(e,t))})},i.equals=function(t,n,r){return t.isSome()&&n.isSome()?r(t.get(),n.get()):t.tag===n.tag},i.fromJSON=function(t){return"None"===t.tag?s.None():s.Some(t.value)},i.prototype.__boxed_type__="Option";var a,c=Object.create(null,Object.getOwnPropertyDescriptors(i.prototype)),f=((a=Object.create(c)).tag="None",a),s=i,l=/*#__PURE__*/function(){function t(){}var n=t.prototype;return n.map=function(t){return"Ok"===this.tag?v.Ok(t(this.value)):this},n.mapError=function(t){return"Ok"===this.tag?this:v.Error(t(this.error))},n.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},n.flatMapError=function(t){return"Ok"===this.tag?this:t(this.error)},n.get=function(){return this.value},n.getError=function(){return this.error},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.error)},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.error),this},n.toOption=function(){return"Ok"===this.tag?s.Some(this.value):f},n.isOk=function(){return"Ok"===this.tag},n.isError=function(){return"Error"===this.tag},n.toJSON=function(){return this.match({Ok:function(t){var n;return(n={})[o]="Result",n.tag="Ok",n.value=t,n},Error:function(t){var n;return(n={})[o]="Result",n.tag="Error",n.error=t,n}})},t}();l.P={Ok:function(t){return{tag:"Ok",value:t}},Error:function(t){return{tag:"Error",error:t}}},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.isResult=function(t){return null!=t&&"Result"===t.__boxed_type__},l.fromExecution=function(t){try{return v.Ok(t())}catch(t){return v.Error(t)}},l.fromPromise=function(t){try{return Promise.resolve(function(n,r){try{var e=Promise.resolve(t).then(function(t){return v.Ok(t)})}catch(t){return r(t)}return e&&e.then?e.then(void 0,r):e}(0,function(t){return v.Error(t)}))}catch(t){return Promise.reject(t)}},l.fromOption=function(t,n){return t.toResult(n)},l.all=function(t){for(var n,r=t.length,e=v.Ok([]),o=0,u=function(){if(o>=r)return{v:e};var n=t[o];null!=n&&(e=e.flatMap(function(t){return n.map(function(n){return t.push(n),t})})),o++};;)if(n=u())return n.v},l.allFromDict=function(r){var e=t(r);return v.all(n(r)).map(function(t){return Object.fromEntries(u(e,t))})},l.equals=function(t,n,r){return t.tag===n.tag&&(!(!t.isError()||!n.isError())||!(!t.isOk()||!n.isOk())&&r(t.get(),n.get()))},l.fromJSON=function(t){return"Ok"===t.tag?v.Ok(t.value):v.Error(t.error)},l.prototype.__boxed_type__="Result";var h=Object.create(null,Object.getOwnPropertyDescriptors(l.prototype)),v=l,p=function(t,n){return t===n?0:t>n?1:-1},m={__proto__:null,from:Array.from,of:Array.of,isArray:Array.isArray,findMap:function(t,n){for(var r=-1;++r<t.length;){var e=n(t[r]);if(e.isSome())return e}return s.None()},filterMap:function(t,n){var r=[];return t.forEach(function(t){var e=n(t);e.isSome()&&r.push(e.get())}),r},find:function(t,n){for(var r=-1;++r<t.length;){var e=t[r];if(n(e))return s.Some(e)}return s.None()},findIndex:function(t,n){for(var r=-1;++r<t.length;)if(n(t[r]))return s.Some(r);return s.None()},binarySearchBy:function(t,n,r){if(void 0===r&&(r=p),0===t.length)return-1;for(var e=0,o=t.length-1;;){var u=e+(o-e)/2|0;if(u===e||u===o)return o;var i=r(n,t[u]);if(0===i)return u;i>0?e=u:i<0&&(o=u)}},unzip:function(t){for(var n=t.length,r=Array(n),e=Array(n),o=-1;++o<n;){var u=t[o];void 0!==u&&(r[o]=u[0],e[o]=u[1])}return[r,e]},zip:u},O=/*#__PURE__*/function(){function t(){}var n=t.prototype;return n.map=function(t){return this===d||this===k?this:y.Done(t(this.value))},n.flatMap=function(t){return this===d||this===k?this:t(this.value)},n.mapOkToResult=function(t){return this.map(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return n}})})},n.mapErrorToResult=function(t){return this.map(function(n){return n.match({Error:function(n){return t(n)},Ok:function(){return n}})})},n.mapOk=function(t){return this.map(function(n){return n.match({Ok:function(n){return v.Ok(t(n))},Error:function(){return n}})})},n.mapError=function(t){return this.map(function(n){return n.match({Ok:function(){return n},Error:function(n){return v.Error(t(n))}})})},n.flatMapOk=function(t){return this.flatMap(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return y.Done(n)}})})},n.flatMapError=function(t){return this.flatMap(function(n){return n.match({Ok:function(){return y.Done(n)},Error:function(n){return t(n)}})})},n.get=function(){return this.value},n.getWithDefault=function(t){return this===d||this===k?t:this.value},n.match=function(t){return this===d?t.NotAsked():this===k?t.Loading():t.Done(this.value)},n.tap=function(t){return t(this),this},n.toOption=function(){return this===d||this===k?s.None():s.Some(this.value)},n.isDone=function(){return this!==d&&this!==k},n.isLoading=function(){return this===k},n.isNotAsked=function(){return this===d},n.toJSON=function(){return this.match({NotAsked:function(){var t;return(t={})[o]="AsyncData",t.tag="NotAsked",t},Loading:function(){var t;return(t={})[o]="AsyncData",t.tag="Loading",t},Done:function(t){var n;return(n={})[o]="AsyncData",n.tag="Done",n.value=t,n}})},t}();O.P={Done:function(t){return{tag:"Done",value:t}},NotAsked:{tag:"NotAsked"},Loading:{tag:"Loading"}},O.Done=function(t){var n=Object.create(_);return n.tag="Done",n.value=t,n},O.Loading=function(){return k},O.NotAsked=function(){return d},O.all=function(t){for(var n,r=t.length,e=y.Done([]),o=0,u=function(){if(o>=r)return{v:e};var n=t[o];null!=n&&(e=e.flatMap(function(t){return n.map(function(n){return t.push(n),t})})),o++};;)if(n=u())return n.v},O.allFromDict=function(r){var e=t(r);return y.all(n(r)).map(function(t){return Object.fromEntries(u(e,t))})},O.equals=function(t,n,r){return"Done"===t.tag&&"Done"===n.tag?r(t.value,n.value):t.tag===n.tag},O.isAsyncData=function(t){return null!=t&&"AsyncData"===t.__boxed_type__},O.fromJSON=function(t){return"NotAsked"===t.tag?y.NotAsked():"Loading"===t.tag?y.Loading():y.Done(t.value)},O.prototype.__boxed_type__="AsyncData";var g,_=Object.create(null,Object.getOwnPropertyDescriptors(O.prototype)),k=((g=Object.create(_)).tag="Loading",g),d=function(){var t=Object.create(_);return t.tag="NotAsked",t}(),y=O,E=/*#__PURE__*/function(){function t(){this._state=void 0,this._state={tag:"Pending"}}t.fromPromise=function(t){return N.make(function(n){t.then(function(t){return n(v.Ok(t))},function(t){return n(v.Error(t))})})};var n=t.prototype;return n.onResolve=function(t){var n;"Pending"===this._state.tag?(this._state.resolveCallbacks=null!=(n=this._state.resolveCallbacks)?n:[],this._state.resolveCallbacks.push(t)):"Resolved"===this._state.tag&&t(this._state.value)},n.onCancel=function(t){var n;"Pending"===this._state.tag?(this._state.cancelCallbacks=null!=(n=this._state.cancelCallbacks)?n:[],this._state.cancelCallbacks.push(t)):"Cancelled"===this._state.tag&&t()},n.cancel=function(){if("Pending"===this._state.tag){var t=this._state,n=t.cancel,r=t.cancelCallbacks;this._state={tag:"Cancelled"},null!=n&&n(),null==r||r.forEach(function(t){return t()})}},n.map=function(t,n){var r=this;void 0===n&&(n=!1);var e=N.make(function(e){if(r.onResolve(function(n){e(t(n))}),n)return function(){r.cancel()}});return this.onCancel(function(){e.cancel()}),e},n.then=function(t){return this.onResolve(t),this},n.flatMap=function(t,n){var r=this;void 0===n&&(n=!1);var e=N.make(function(o){if(r.onResolve(function(n){var r=t(n);r.onResolve(o),r.onCancel(function(){return e.cancel()})}),n)return function(){r.cancel()}});return this.onCancel(function(){e.cancel()}),e},n.tap=function(t){return this.onResolve(t),this},n.tapOk=function(t){return this.onResolve(function(n){n.match({Ok:function(n){return t(n)},Error:function(){}})}),this},n.tapError=function(t){return this.onResolve(function(n){n.match({Ok:function(){},Error:function(n){return t(n)}})}),this},n.mapOkToResult=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.mapErrorToResult=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Error:function(n){return t(n)},Ok: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 v.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 v.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 N.value(n)}})},n)},n.flatMapError=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(){return N.value(n)},Error:function(n){return t(n)}})},n)},n.toPromise=function(){var t=this;return new Promise(function(n){t.onResolve(n)})},n.resultToPromise=function(){var t=this;return new Promise(function(n,r){t.onResolve(function(t){t.match({Ok:n,Error:r})})})},t}();E.make=function(t){var n=Object.create(b);return n._state={tag:"Pending"},n._state.cancel=t(function(t){if("Pending"===n._state.tag){var r=n._state.resolveCallbacks;n._state={tag:"Resolved",value:t},null==r||r.forEach(function(n){return n(t)})}}),n},E.isFuture=function(t){return null!=t&&Object.prototype.isPrototypeOf.call(b,t)},E.value=function(t){var n=Object.create(b);return n._state={tag:"Resolved",value:t},n},E.all=function(t,n){void 0===n&&(n=!1);for(var r,e=t.length,o=N.value([]),u=0,i=function(){if(u>=e)return{v:o};var r=t[u];null!=r&&(o=o.flatMap(function(t){return r.map(function(n){return t.push(n),t},n)},n)),u++};;)if(r=i())return r.v},E.allFromDict=function(r){var e=t(r);return N.all(n(r)).map(function(t){return Object.fromEntries(u(e,t))})};var b=Object.create(null,Object.getOwnPropertyDescriptors(E.prototype)),N=E,S={make:function(){var t;return[N.make(function(n){t=n}),t]}},D=Symbol("NOT_COMPUTED");function j(){return j=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t},j.apply(this,arguments)}var A={__proto__:null,encode:function(t,n){return JSON.stringify(t,function(t,n){return"string"==typeof n[o]?j({},n,{__boxed_type__:n[o]}):n},n)},decode:function(t){return JSON.parse(t,function(t,n){return null==n?n:"Option"===n.__boxed_type__?s.fromJSON(n):"Result"===n.__boxed_type__?v.fromJSON(n):"AsyncData"===n.__boxed_type__?y.fromJSON(n):n})}};exports.Array=m,exports.AsyncData=y,exports.Deferred=S,exports.Dict=e,exports.Future=N,exports.Lazy=function(t){var n={contents:D};return{get:function(){return n.contents===D&&(n.contents=t()),n.contents}}},exports.Option=s,exports.Result=v,exports.Serializer=A; | ||
var t=function(t){return Object.keys(t)},n=function(t){return Object.values(t)},r=Object.prototype.hasOwnProperty,e={__proto__:null,fromEntries:Object.fromEntries,entries:function(t){return Object.entries(t)},keys:t,values:n,fromOptional:function(t){var n={};for(var e in t)if(r.call(t,e)){var o=t[e];if(void 0===o)continue;o.isSome()&&(n[e]=o.get())}return n}},o=Symbol.for("__boxed_type__"),u=function(t,n){for(var r=Math.min(t.length,n.length),e=Array(r),o=-1;++o<r;)e[o]=[t[o],n[o]];return e},i=/*#__PURE__*/function(){function t(){}var n=t.prototype;return n.map=function(t){return this===f?this:s.Some(t(this.value))},n.flatMap=function(t){return this===f?this:t(this.value)},n.filter=function(t){return this===f||t(this.value)?this:f},n.get=function(){return this.value},n.getWithDefault=function(t){return this===f?t:this.value},n.getOr=function(t){return this===f?t:this.value},n.match=function(t){return this===f?t.None():t.Some(this.value)},n.tap=function(t){return t(this),this},n.toUndefined=function(){if(this!==f)return this.value},n.toNull=function(){return this===f?null:this.value},n.toResult=function(t){return this.match({Some:function(t){return v.Ok(t)},None:function(){return v.Error(t)}})},n.isSome=function(){return this!==f},n.isNone=function(){return this===f},n.toJSON=function(){return this.match({None:function(){var t;return(t={})[o]="Option",t.tag="None",t},Some:function(t){var n;return(n={})[o]="Option",n.tag="Some",n.value=t,n}})},t}();i.P={Some:function(t){return{tag:"Some",value:t}},None:{tag:"None"}},i.Some=function(t){var n=Object.create(c);return n.tag="Some",n.value=t,n},i.None=function(){return f},i.isOption=function(t){return null!=t&&"Option"===t.__boxed_type__},i.fromNullable=function(t){return null==t?f:s.Some(t)},i.fromNull=function(t){return null===t?f:s.Some(t)},i.fromUndefined=function(t){return void 0===t?f:s.Some(t)},i.all=function(t){for(var n,r=t.length,e=s.Some([]),o=0,u=function(){if(o>=r)return{v:e};var n=t[o];null!=n&&(e=e.flatMap(function(t){return n.map(function(n){return t.push(n),t})})),o++};;)if(n=u())return n.v},i.allFromDict=function(r){var e=t(r);return s.all(n(r)).map(function(t){return Object.fromEntries(u(e,t))})},i.equals=function(t,n,r){return t.isSome()&&n.isSome()?r(t.get(),n.get()):t.tag===n.tag},i.fromJSON=function(t){return"None"===t.tag?s.None():s.Some(t.value)},i.prototype.__boxed_type__="Option";var a,c=Object.create(null,Object.getOwnPropertyDescriptors(i.prototype)),f=((a=Object.create(c)).tag="None",a),s=i,l=/*#__PURE__*/function(){function t(){}var n=t.prototype;return n.map=function(t){return"Ok"===this.tag?v.Ok(t(this.value)):this},n.mapError=function(t){return"Ok"===this.tag?this:v.Error(t(this.error))},n.flatMap=function(t){return"Ok"===this.tag?t(this.value):this},n.flatMapError=function(t){return"Ok"===this.tag?this:t(this.error)},n.get=function(){return this.value},n.getError=function(){return this.error},n.getWithDefault=function(t){return"Ok"===this.tag?this.value:t},n.getOr=function(t){return"Ok"===this.tag?this.value:t},n.match=function(t){return"Ok"===this.tag?t.Ok(this.value):t.Error(this.error)},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.error),this},n.toOption=function(){return"Ok"===this.tag?s.Some(this.value):f},n.isOk=function(){return"Ok"===this.tag},n.isError=function(){return"Error"===this.tag},n.toJSON=function(){return this.match({Ok:function(t){var n;return(n={})[o]="Result",n.tag="Ok",n.value=t,n},Error:function(t){var n;return(n={})[o]="Result",n.tag="Error",n.error=t,n}})},t}();l.P={Ok:function(t){return{tag:"Ok",value:t}},Error:function(t){return{tag:"Error",error:t}}},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.isResult=function(t){return null!=t&&"Result"===t.__boxed_type__},l.fromExecution=function(t){try{return v.Ok(t())}catch(t){return v.Error(t)}},l.fromPromise=function(t){try{return Promise.resolve(function(n,r){try{var e=Promise.resolve(t).then(function(t){return v.Ok(t)})}catch(t){return r(t)}return e&&e.then?e.then(void 0,r):e}(0,function(t){return v.Error(t)}))}catch(t){return Promise.reject(t)}},l.fromOption=function(t,n){return t.toResult(n)},l.all=function(t){for(var n,r=t.length,e=v.Ok([]),o=0,u=function(){if(o>=r)return{v:e};var n=t[o];null!=n&&(e=e.flatMap(function(t){return n.map(function(n){return t.push(n),t})})),o++};;)if(n=u())return n.v},l.allFromDict=function(r){var e=t(r);return v.all(n(r)).map(function(t){return Object.fromEntries(u(e,t))})},l.equals=function(t,n,r){return t.tag===n.tag&&(!(!t.isError()||!n.isError())||!(!t.isOk()||!n.isOk())&&r(t.get(),n.get()))},l.fromJSON=function(t){return"Ok"===t.tag?v.Ok(t.value):v.Error(t.error)},l.prototype.__boxed_type__="Result";var h=Object.create(null,Object.getOwnPropertyDescriptors(l.prototype)),v=l,p=function(t,n){return t===n?0:t>n?1:-1},m={__proto__:null,from:Array.from,of:Array.of,isArray:Array.isArray,findMap:function(t,n){for(var r=-1;++r<t.length;){var e=n(t[r]);if(e.isSome())return e}return s.None()},filterMap:function(t,n){var r=[];return t.forEach(function(t){var e=n(t);e.isSome()&&r.push(e.get())}),r},find:function(t,n){for(var r=-1;++r<t.length;){var e=t[r];if(n(e))return s.Some(e)}return s.None()},findIndex:function(t,n){for(var r=-1;++r<t.length;)if(n(t[r]))return s.Some(r);return s.None()},binarySearchBy:function(t,n,r){if(void 0===r&&(r=p),0===t.length)return-1;for(var e=0,o=t.length-1;;){var u=e+(o-e)/2|0;if(u===e||u===o)return o;var i=r(n,t[u]);if(0===i)return u;i>0?e=u:i<0&&(o=u)}},unzip:function(t){for(var n=t.length,r=Array(n),e=Array(n),o=-1;++o<n;){var u=t[o];void 0!==u&&(r[o]=u[0],e[o]=u[1])}return[r,e]},zip:u},O=/*#__PURE__*/function(){function t(){}var n=t.prototype;return n.map=function(t){return this===d||this===k?this:y.Done(t(this.value))},n.flatMap=function(t){return this===d||this===k?this:t(this.value)},n.mapOkToResult=function(t){return this.map(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return n}})})},n.mapErrorToResult=function(t){return this.map(function(n){return n.match({Error:function(n){return t(n)},Ok:function(){return n}})})},n.mapOk=function(t){return this.map(function(n){return n.match({Ok:function(n){return v.Ok(t(n))},Error:function(){return n}})})},n.mapError=function(t){return this.map(function(n){return n.match({Ok:function(){return n},Error:function(n){return v.Error(t(n))}})})},n.flatMapOk=function(t){return this.flatMap(function(n){return n.match({Ok:function(n){return t(n)},Error:function(){return y.Done(n)}})})},n.flatMapError=function(t){return this.flatMap(function(n){return n.match({Ok:function(){return y.Done(n)},Error:function(n){return t(n)}})})},n.get=function(){return this.value},n.getWithDefault=function(t){return this===d||this===k?t:this.value},n.getOr=function(t){return this===d||this===k?t:this.value},n.match=function(t){return this===d?t.NotAsked():this===k?t.Loading():t.Done(this.value)},n.tap=function(t){return t(this),this},n.toOption=function(){return this===d||this===k?s.None():s.Some(this.value)},n.isDone=function(){return this!==d&&this!==k},n.isLoading=function(){return this===k},n.isNotAsked=function(){return this===d},n.toJSON=function(){return this.match({NotAsked:function(){var t;return(t={})[o]="AsyncData",t.tag="NotAsked",t},Loading:function(){var t;return(t={})[o]="AsyncData",t.tag="Loading",t},Done:function(t){var n;return(n={})[o]="AsyncData",n.tag="Done",n.value=t,n}})},t}();O.P={Done:function(t){return{tag:"Done",value:t}},NotAsked:{tag:"NotAsked"},Loading:{tag:"Loading"}},O.Done=function(t){var n=Object.create(_);return n.tag="Done",n.value=t,n},O.Loading=function(){return k},O.NotAsked=function(){return d},O.all=function(t){for(var n,r=t.length,e=y.Done([]),o=0,u=function(){if(o>=r)return{v:e};var n=t[o];null!=n&&(e=e.flatMap(function(t){return n.map(function(n){return t.push(n),t})})),o++};;)if(n=u())return n.v},O.allFromDict=function(r){var e=t(r);return y.all(n(r)).map(function(t){return Object.fromEntries(u(e,t))})},O.equals=function(t,n,r){return"Done"===t.tag&&"Done"===n.tag?r(t.value,n.value):t.tag===n.tag},O.isAsyncData=function(t){return null!=t&&"AsyncData"===t.__boxed_type__},O.fromJSON=function(t){return"NotAsked"===t.tag?y.NotAsked():"Loading"===t.tag?y.Loading():y.Done(t.value)},O.prototype.__boxed_type__="AsyncData";var g,_=Object.create(null,Object.getOwnPropertyDescriptors(O.prototype)),k=((g=Object.create(_)).tag="Loading",g),d=function(){var t=Object.create(_);return t.tag="NotAsked",t}(),y=O,E=/*#__PURE__*/function(){function t(){this._state=void 0,this._state={tag:"Pending"}}t.fromPromise=function(t){return N.make(function(n){t.then(function(t){return n(v.Ok(t))},function(t){return n(v.Error(t))})})};var n=t.prototype;return n.onResolve=function(t){var n;"Pending"===this._state.tag?(this._state.resolveCallbacks=null!=(n=this._state.resolveCallbacks)?n:[],this._state.resolveCallbacks.push(t)):"Resolved"===this._state.tag&&t(this._state.value)},n.onCancel=function(t){var n;"Pending"===this._state.tag?(this._state.cancelCallbacks=null!=(n=this._state.cancelCallbacks)?n:[],this._state.cancelCallbacks.push(t)):"Cancelled"===this._state.tag&&t()},n.cancel=function(){if("Pending"===this._state.tag){var t=this._state,n=t.cancel,r=t.cancelCallbacks;this._state={tag:"Cancelled"},null!=n&&n(),null==r||r.forEach(function(t){return t()})}},n.map=function(t,n){var r=this;void 0===n&&(n=!1);var e=N.make(function(e){if(r.onResolve(function(n){e(t(n))}),n)return function(){r.cancel()}});return this.onCancel(function(){e.cancel()}),e},n.then=function(t){return this.onResolve(t),this},n.flatMap=function(t,n){var r=this;void 0===n&&(n=!1);var e=N.make(function(o){if(r.onResolve(function(n){var r=t(n);r.onResolve(o),r.onCancel(function(){return e.cancel()})}),n)return function(){r.cancel()}});return this.onCancel(function(){e.cancel()}),e},n.tap=function(t){return this.onResolve(t),this},n.tapOk=function(t){return this.onResolve(function(n){n.match({Ok:function(n){return t(n)},Error:function(){}})}),this},n.tapError=function(t){return this.onResolve(function(n){n.match({Ok:function(){},Error:function(n){return t(n)}})}),this},n.mapOkToResult=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.mapErrorToResult=function(t,n){return void 0===n&&(n=!1),this.map(function(n){return n.match({Error:function(n){return t(n)},Ok: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 v.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 v.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 N.value(n)}})},n)},n.flatMapError=function(t,n){return void 0===n&&(n=!1),this.flatMap(function(n){return n.match({Ok:function(){return N.value(n)},Error:function(n){return t(n)}})},n)},n.toPromise=function(){var t=this;return new Promise(function(n){t.onResolve(n)})},n.resultToPromise=function(){var t=this;return new Promise(function(n,r){t.onResolve(function(t){t.match({Ok:n,Error:r})})})},t}();E.make=function(t){var n=Object.create(b);return n._state={tag:"Pending"},n._state.cancel=t(function(t){if("Pending"===n._state.tag){var r=n._state.resolveCallbacks;n._state={tag:"Resolved",value:t},null==r||r.forEach(function(n){return n(t)})}}),n},E.isFuture=function(t){return null!=t&&Object.prototype.isPrototypeOf.call(b,t)},E.value=function(t){var n=Object.create(b);return n._state={tag:"Resolved",value:t},n},E.all=function(t,n){void 0===n&&(n=!1);for(var r,e=t.length,o=N.value([]),u=0,i=function(){if(u>=e)return{v:o};var r=t[u];null!=r&&(o=o.flatMap(function(t){return r.map(function(n){return t.push(n),t},n)},n)),u++};;)if(r=i())return r.v},E.allFromDict=function(r){var e=t(r);return N.all(n(r)).map(function(t){return Object.fromEntries(u(e,t))})};var b=Object.create(null,Object.getOwnPropertyDescriptors(E.prototype)),N=E,S={make:function(){var t;return[N.make(function(n){t=n}),t]}},D=Symbol("NOT_COMPUTED");function j(){return j=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])}return t},j.apply(this,arguments)}var A={__proto__:null,encode:function(t,n){return JSON.stringify(t,function(t,n){return"string"==typeof n[o]?j({},n,{__boxed_type__:n[o]}):n},n)},decode:function(t){return JSON.parse(t,function(t,n){return null==n?n:"Option"===n.__boxed_type__?s.fromJSON(n):"Result"===n.__boxed_type__?v.fromJSON(n):"AsyncData"===n.__boxed_type__?y.fromJSON(n):n})}};exports.Array=m,exports.AsyncData=y,exports.Deferred=S,exports.Dict=e,exports.Future=N,exports.Lazy=function(t){var n={contents:D};return{get:function(){return n.contents===D&&(n.contents=t()),n.contents}}},exports.Option=s,exports.Result=v,exports.Serializer=A; | ||
//# sourceMappingURL=Boxed.js.map |
@@ -67,2 +67,8 @@ import { JsonOption, JsonResult, LooseRecord } from "./types"; | ||
/** | ||
* Return the value if present, and the fallback otherwise | ||
* | ||
* (Option\<A>, A) => A | ||
*/ | ||
getOr(this: Option<A>, defaultValue: A): A; | ||
/** | ||
* Explodes the Option given its case | ||
@@ -184,2 +190,8 @@ */ | ||
/** | ||
* Return the value if present, and the fallback otherwise | ||
* | ||
* (Result\<A, E>, A) => A | ||
*/ | ||
getOr(this: Result<A, E>, defaultValue: A): A; | ||
/** | ||
* Explodes the Result given its case | ||
@@ -186,0 +198,0 @@ */ |
@@ -0,1 +1,7 @@ | ||
# 2.2.1 | ||
Features: | ||
- Add `getOr` alias for `getWithDefault` (4c51724) | ||
# 2.2.0 | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "@swan-io/boxed", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Utility types for functional TypeScript", |
@@ -9,5 +9,5 @@ <img width="108" alt="@swan-io/boxed logo" src="https://github.com/swan-io/boxed/blob/main/docs/static/img/logo.svg?raw=true"> | ||
> Utility types for functional TypeScript | ||
> Essential building-blocks for functional & safe TypeScript code | ||
**Boxed** provides functional utility types and functions, while focusing on ease-of-use. | ||
**Boxed** provides essential building-blocks (in the form of types and functions) so that you can write functional, safe TypeScript code. | ||
@@ -14,0 +14,0 @@ ## Design principles |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176274
638