@nobrayner/orf
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -309,7 +309,8 @@ interface IResult<T, E> { | ||
type Error<T, E> = __Error<T, E>; | ||
type JsonResult<T, E> = { | ||
type JsonOk<T, _E> = { | ||
__orf_type__: "Result"; | ||
tag: "Ok"; | ||
value: T; | ||
} | { | ||
}; | ||
type JsonError<_T, E> = { | ||
__orf_type__: "Result"; | ||
@@ -319,2 +320,3 @@ tag: "Error"; | ||
}; | ||
type JsonResult<T, E> = JsonOk<T, E> | JsonError<T, E>; | ||
type Result<T, E> = Ok<T, E> | Error<T, E>; | ||
@@ -784,10 +786,12 @@ declare namespace Result { | ||
type None<T> = __None<T>; | ||
type JsonOption<T> = { | ||
type JsonSome<T> = { | ||
__orf_type__: "Option"; | ||
} & ({ | ||
tag: "Some"; | ||
value: T; | ||
} | { | ||
}; | ||
type JsonNone<_T> = { | ||
__orf_type__: "Option"; | ||
tag: "None"; | ||
}); | ||
}; | ||
type JsonOption<T> = JsonSome<T> | JsonNone<T>; | ||
type Option<T> = Some<T> | None<T>; | ||
@@ -794,0 +798,0 @@ declare namespace Option { |
@@ -1,1 +0,1 @@ | ||
"use strict";var W=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var ue=(u,e)=>{for(var t in e)W(u,t,{get:e[t],enumerable:!0})},le=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of ne(e))!oe.call(u,l)&&l!==t&&W(u,l,{get:()=>e[l],enumerable:!(n=re(e,l))||n.enumerable});return u};var ae=u=>le(W({},"__esModule",{value:!0}),u);var X=(u,e,t)=>{if(!e.has(u))throw TypeError("Cannot "+t)};var r=(u,e,t)=>(X(u,e,"read from private field"),t?t.call(u):e.get(u)),N=(u,e,t)=>{if(e.has(u))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(u):e.set(u,t)},y=(u,e,t,n)=>(X(u,e,"write to private field"),n?n.call(u,t):e.set(u,t),t);var J=(u,e,t)=>(X(u,e,"access private method"),t);var Z=(u,e,t)=>new Promise((n,l)=>{var k=S=>{try{g(t.next(S))}catch(i){l(i)}},c=S=>{try{g(t.throw(S))}catch(i){l(i)}},g=S=>S.done?n(S.value):Promise.resolve(S.value).then(k,c);g((t=t.apply(u,e)).next())});var se={};ue(se,{Future:()=>v,Option:()=>d,Result:()=>h});module.exports=ae(se);var Y=Error,h;(S=>{function u(i){return Object.freeze(new z(i))}S.Ok=u;function e(i){return Object.freeze(new P(i))}S.Error=e;function t(i){return i instanceof z||i instanceof P}S.isResult=t;function n(i,F){var O;try{return u(i())}catch(b){return e((O=F==null?void 0:F(b))!=null?O:b)}}S.fromExecution=n;function l(i,F){return Z(this,null,function*(){var O;try{return u(yield i)}catch(b){return e((O=F==null?void 0:F(b))!=null?O:b)}})}S.fromAwaitable=l;function k(i){let F=[];for(let O of i){if(O.isError())return O;F.push(O.unwrap())}return u(F)}S.all=k;function c(i){let F={};for(let O in i){let b=i[O];if(b.isError())return b;F[O]=b.unwrap()}return u(F)}S.allFromDict=c;function g(i){if(i.__orf_type__!=="Result"&&!("tag"in i))throw new Y("Invalid Result JSON");if(i.tag==="Ok")return u(i.value);if(i.tag==="Error")return e(i.error);throw new Y("Invalid Result JSON")}S.fromJSON=g})(h||(h={}));var z=class{constructor(e){this.value=e}isOk(){return!0}isError(){return!this.isOk()}match(e){return e.Ok(this.value)}map(e){return h.Ok(e(this.value))}mapOr(e,t){return t(this.value)}mapOrElse(e,t){return t(this.value)}mapError(e){return this}and(e){return e}andThen(e){return e(this.value)}or(e){return this}orElse(e){return this}tap(e){return e(Object.freeze(structuredClone(this.value))),this}tapError(e){return this}ok(){return d.Some(this.value)}unwrap(){return this.value}unwrapError(){throw new Y("Cannot unwrapError an Ok")}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}toJSON(){return{__orf_type__:"Result",tag:"Ok",value:this.value}}},P=class{constructor(e){this.error=e}isOk(){return!1}isError(){return!this.isOk()}match(e){return e.Error(this.error)}map(e){return this}mapOr(e,t){return e}mapOrElse(e,t){return e()}mapError(e){return h.Error(e(this.error))}and(e){return this}andThen(e){return this}or(e){return e}orElse(e){return e(this.error)}tap(e){return this}tapError(e){return e(Object.freeze(structuredClone(this.error))),this}ok(){return d.None()}unwrap(){throw this.error}unwrapError(){return this.error}unwrapOr(e){return e}unwrapOrElse(e){return e(this.error)}toJSON(){return{__orf_type__:"Result",tag:"Error",error:this.error}}};var d;(k=>{function u(c){return Object.freeze(new q(c))}k.Some=u;function e(){return ie}k.None=e;function t(c){return c instanceof q||c instanceof B}k.isOption=t;function n(c){return c?u(c):e()}k.from=n;function l(c){if(c.__orf_type__!=="Option"&&!("tag"in c))throw new Error("Invalid Option JSON");if(c.tag==="Some")return u(c.value);if(c.tag==="None")return e();throw new Error("Invalid Option JSON")}k.fromJSON=l})(d||(d={}));var q=class{constructor(e){this.value=e}isSome(){return!0}isNone(){return!this.isSome()}match(e){return e.Some(this.value)}map(e){return d.Some(e(this.value))}mapOr(e,t){return t(this.value)}mapOrElse(e,t){return t(this.value)}and(e){return e}andThen(e){return e(this.value)}or(e){return this}orElse(e){return this}tap(e){return e(Object.freeze(structuredClone(this.value))),this}unwrap(){return this.value}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}okOr(e){return h.Ok(this.value)}okOrElse(e){return h.Ok(this.value)}toJSON(){return{__orf_type__:"Option",tag:"Some",value:this.value}}},B=class{isSome(){return!1}isNone(){return!this.isSome()}match(e){return e.None()}map(e){return this}mapOr(e,t){return e}mapOrElse(e,t){return e()}and(e){return this}andThen(e){return this}or(e){return e}orElse(e){return e()}tap(e){return this}unwrap(){throw new Error("Cannot unwrap None")}unwrapOr(e){return e}unwrapOrElse(e){return e()}okOr(e){return h.Error(e)}okOrElse(e){return h.Error(e())}toJSON(){return{__orf_type__:"Option",tag:"None"}}},ie=Object.freeze(new B);var v;(V=>{function u(o){return new K({tag:"completed",value:o})}V.value=u;function e(o){return new C({tag:"completed",value:h.Ok(o)})}V.success=e;function t(o){return new C({tag:"completed",value:h.Error(o)})}V.fail=t;function n(o){return o instanceof K}V.isFuture=n;function l(o){return o instanceof C}V.isFallibleFuture=l;function k(o){return o instanceof C?o:o instanceof Promise?V.makeFallible((p,U)=>{o.then(p).catch(U)}):o.match({Ok:p=>e(p),Error:p=>t(p)})}V.fromFallible=k;function c(o,p){return new K({tag:"pending",execute:o},p)}V.make=c;function g(o){return new K({tag:"pending",execute:o},{lazy:!0})}V.lazy=g;function S(o,p){return new C({tag:"pending",execute:o},p)}V.makeFallible=S;function i(o){return new C({tag:"pending",execute:o},{lazy:!0})}V.lazyFallible=i;function F(o){return new K({tag:"pending",execute:p=>{let U=setTimeout(p,o);return()=>{clearTimeout(U)}}})}V.wait=F;function O(o){if(!o.some(V.isFallibleFuture)){let w=V.make(_=>{let E=new Array(o.length),R=0;return o.forEach((f,x)=>{f.onResolved(m=>{E[x]=m,R+=1,R===o.length&&_(E)})}),()=>o.forEach(f=>f.cancel())});return o.forEach(_=>_.onCancelled(w.cancel.bind(w))),w}let U=V.makeFallible((w,_)=>{let E=new Array(o.length),R=0;for(let f=0;f<o.length;++f){let x=o[f];V.isFuture(x)&&(x=x.neverError()),x.onResolved(m=>{E[f]=m,R+=1,R===o.length&&h.all(E).match({Ok:w,Error:_})})}return()=>o.forEach(f=>f.cancel())});return o.forEach(w=>w.onCancelled(U.cancel.bind(U))),U}V.all=O;function b(o){let p=V.make(U=>{let w=new Array(o.length),_=0;return o.forEach((E,R)=>{E.onResolved(f=>{w[R]=f,_+=1,_===o.length&&U(w)})}),()=>o.forEach(E=>E.cancel())});return o.forEach(U=>U.onCancelled(p.cancel.bind(p))),p}V.allResolved=b;function ce(o){let p=Object.values(o),U=p.length;if(!p.some(V.isFallibleFuture)){let E=V.make(R=>{let f={},x=0;for(let m in o)o[m].onResolved(Q=>{f[m]=Q,x+=1,x===U&&R(f)});return()=>{for(let m of p)m.cancel()}});for(let R of p)R.onCancelled(E.cancel.bind(E));return E}let _=V.makeFallible((E,R)=>{let f={},x=0;for(let m in o){let D=o[m];V.isFuture(D)&&(D=D.neverError()),D.onResolved(Q=>{f[m]=Q,x+=1,x===U&&h.allFromDict(f).match({Ok:E,Error:R})})}return()=>{for(let m of p)m.cancel()}});for(let E of p)E.onCancelled(_.cancel.bind(_));return _}V.allFromDict=ce})(v||(v={}));var s,G,$,K=class{constructor(e,t){N(this,G);N(this,s,void 0);y(this,s,e),t!=null&&t.lazy||this.then()}onResolved(e){var t;r(this,s).tag==="pending"?(r(this,s).resolve_callbacks=(t=r(this,s).resolve_callbacks)!=null?t:[],r(this,s).resolve_callbacks.push(e)):r(this,s).tag==="completed"&&e(r(this,s).value)}onCancelled(e){var t;r(this,s).tag==="pending"?(r(this,s).cancel_callbacks=(t=r(this,s).cancel_callbacks)!=null?t:[],r(this,s).cancel_callbacks.push(e)):r(this,s).tag==="cancelled"&&e()}cancel(){if(r(this,s).tag==="pending"){let{cancel:e,cancel_callbacks:t}=r(this,s);y(this,s,{tag:"cancelled"}),e==null||e(),t==null||t.forEach(n=>n())}}then(e){if(r(this,s).tag==="pending"&&r(this,s).execute){let t=r(this,s).execute(J(this,G,$).bind(this));r(this,s).execute=null,t&&(r(this,s).cancel=t)}return e&&(this.onResolved(t=>e(d.Some(t))),this.onCancelled(()=>e(d.None()))),this}map(e){let t=v.make(n=>(this.onResolved(l=>{n(e(l))}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}tap(e){return this.onResolved(e),this}neverError(){let e=v.makeFallible((t,n)=>(this.onResolved(t),this.cancel.bind(this)));return this.onCancelled(e.cancel.bind(e)),e}unwrap(){let e=new A({tag:"pending",execute:t=>{this.onResolved(t)}});return this.onCancelled(e.cancel.bind(e)),e}unwrapOr(e){return new A({tag:"pending",execute:n=>(this.onResolved(l=>{n(l)}),this.onCancelled(()=>{n(e)}),()=>{n(e)})})}unwrapOrElse(e){return new A({tag:"pending",execute:n=>(this.onResolved(l=>{n(l)}),this.onCancelled(()=>{n(e())}),()=>{n(e())})})}};s=new WeakMap,G=new WeakSet,$=function(e){if(r(this,s).tag==="pending"){let{resolve_callbacks:t}=r(this,s);y(this,s,{tag:"completed",value:e}),t==null||t.forEach(n=>n(e))}};var a,H,j,L,ee,C=class{constructor(e,t){N(this,H);N(this,L);N(this,a,void 0);y(this,a,e),t!=null&&t.lazy||this.then()}onResolved(e){var t;r(this,a).tag==="pending"?(r(this,a).resolve_callbacks=(t=r(this,a).resolve_callbacks)!=null?t:[],r(this,a).resolve_callbacks.push(e)):r(this,a).tag==="completed"&&e(r(this,a).value)}onSucceeded(e){this.onResolved(t=>{t.match({Ok:e,Error:()=>{}})})}onFailed(e){this.onResolved(t=>{t.match({Ok:()=>{},Error:e})})}onCancelled(e){var t;r(this,a).tag==="pending"?(r(this,a).cancel_callbacks=(t=r(this,a).cancel_callbacks)!=null?t:[],r(this,a).cancel_callbacks.push(e)):r(this,a).tag==="cancelled"&&e()}cancel(){if(r(this,a).tag==="pending"){let{cancel:e,cancel_callbacks:t}=r(this,a);y(this,a,{tag:"cancelled"}),e==null||e(),t==null||t.forEach(n=>n())}}then(e){if(r(this,a).tag==="pending"&&r(this,a).execute){let t=r(this,a).execute(J(this,H,j).bind(this),J(this,L,ee).bind(this));r(this,a).execute=null,t&&(r(this,a).cancel=t)}return e&&(this.onResolved(t=>e(d.Some(t))),this.onCancelled(()=>e(d.None()))),this}map(e){let t=v.makeFallible((n,l)=>(this.onResolved(k=>{k.match({Ok:c=>{n(e(c))},Error:l})}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}mapError(e){let t=v.makeFallible((n,l)=>(this.onResolved(k=>{k.match({Ok:n,Error:c=>{l(e(c))}})}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}andThen(e){let t=v.makeFallible((n,l)=>(this.onResolved(k=>{k.match({Ok:c=>{let g=v.fromFallible(e(c));g.onSucceeded(n),g.onFailed(l)},Error:l})}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}orElse(e){let t=v.makeFallible((n,l)=>(this.onResolved(k=>{k.match({Ok:n,Error:c=>{let g=v.fromFallible(e(c));g.onSucceeded(n),g.onFailed(l)}})}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}tap(e){return this.onSucceeded(e),this}tapError(e){return this.onFailed(e),this}ok(){let e=v.make(t=>(this.onSucceeded(n=>t(d.Some(n))),this.onFailed(()=>t(d.None())),this.cancel.bind(this)));return this.onCancelled(e.cancel.bind(e)),e}unwrap(){let e=new A({tag:"pending",execute:t=>{this.onResolved(t)}});return this.onCancelled(e.cancel.bind(e)),e}unwrapOr(e){return new A({tag:"pending",execute:n=>(this.onResolved(n),this.onCancelled(()=>{n(e)}),()=>{n(e)})})}unwrapOrElse(e){return new A({tag:"pending",execute:n=>(this.onResolved(n),this.onCancelled(()=>{n(e())}),()=>{n(e())})})}match(e){let t=new A({tag:"pending",execute:n=>{this.onResolved(l=>{n(l.match(e))})}});return this.onCancelled(t.cancel.bind(t)),t}};a=new WeakMap,H=new WeakSet,j=function(e){if(r(this,a).tag==="pending"){let{resolve_callbacks:t}=r(this,a),n=h.Ok(e);y(this,a,{tag:"completed",value:n}),t==null||t.forEach(l=>l(n))}},L=new WeakSet,ee=function(e){if(r(this,a).tag==="pending"){let{resolve_callbacks:t}=r(this,a),n=h.Error(e);y(this,a,{tag:"completed",value:n}),t==null||t.forEach(l=>l(n))}};var T,I,M,te,A=class{constructor(e){N(this,M);N(this,T,void 0);N(this,I,void 0);if(y(this,T,e),r(this,T).tag==="pending"&&r(this,T).execute){let t=r(this,T).execute(J(this,M,te).bind(this));r(this,T).execute=null,t&&!r(this,I)&&y(this,I,t)}}onResolved(e){var t;r(this,T).tag==="pending"?(r(this,T).resolve_callbacks=(t=r(this,T).resolve_callbacks)!=null?t:[],r(this,T).resolve_callbacks.push(e)):r(this,T).tag==="completed"&&e(r(this,T).value)}onCancelled(e){r(this,T).tag==="pending"&&!r(this,I)?y(this,I,e):r(this,T).tag==="cancelled"&&!r(this,I)&&e(new Error("Cannot cancel UnwrappedFuture"))}cancel(){r(this,T).tag==="pending"&&(r(this,I)?(r(this,I).call(this,new Error("Cannot cancel UnwrappedFuture")),r(this,T).tag==="pending"&&y(this,T,{tag:"cancelled"})):y(this,T,{tag:"cancelled"}))}then(e,t){return e&&this.onResolved(e),t&&this.onCancelled(t),this}};T=new WeakMap,I=new WeakMap,M=new WeakSet,te=function(e){if(r(this,T).tag==="pending"){let{resolve_callbacks:t}=r(this,T);y(this,T,{tag:"completed",value:e}),t==null||t.forEach(n=>n(e))}};0&&(module.exports={Future,Option,Result}); | ||
"use strict";var W=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var ue=(u,e)=>{for(var t in e)W(u,t,{get:e[t],enumerable:!0})},le=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of ne(e))!oe.call(u,l)&&l!==t&&W(u,l,{get:()=>e[l],enumerable:!(n=re(e,l))||n.enumerable});return u};var ae=u=>le(W({},"__esModule",{value:!0}),u);var X=(u,e,t)=>{if(!e.has(u))throw TypeError("Cannot "+t)};var r=(u,e,t)=>(X(u,e,"read from private field"),t?t.call(u):e.get(u)),N=(u,e,t)=>{if(e.has(u))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(u):e.set(u,t)},y=(u,e,t,n)=>(X(u,e,"write to private field"),n?n.call(u,t):e.set(u,t),t);var D=(u,e,t)=>(X(u,e,"access private method"),t);var Z=(u,e,t)=>new Promise((n,l)=>{var k=S=>{try{g(t.next(S))}catch(i){l(i)}},c=S=>{try{g(t.throw(S))}catch(i){l(i)}},g=S=>S.done?n(S.value):Promise.resolve(S.value).then(k,c);g((t=t.apply(u,e)).next())});var se={};ue(se,{Future:()=>v,Option:()=>d,Result:()=>h});module.exports=ae(se);var Y=Error,h;(S=>{function u(i){return Object.freeze(new z(i))}S.Ok=u;function e(i){return Object.freeze(new P(i))}S.Error=e;function t(i){return i instanceof z||i instanceof P}S.isResult=t;function n(i,F){var O;try{return u(i())}catch(b){return e((O=F==null?void 0:F(b))!=null?O:b)}}S.fromExecution=n;function l(i,F){return Z(this,null,function*(){var O;try{return u(yield i)}catch(b){return e((O=F==null?void 0:F(b))!=null?O:b)}})}S.fromAwaitable=l;function k(i){let F=[];for(let O of i){if(O.isError())return O;F.push(O.unwrap())}return u(F)}S.all=k;function c(i){let F={};for(let O in i){let b=i[O];if(b.isError())return b;F[O]=b.unwrap()}return u(F)}S.allFromDict=c;function g(i){if(i.__orf_type__!=="Result"&&!("tag"in i))throw new Y("Invalid Result JSON");if(i.tag==="Ok")return u(i.value);if(i.tag==="Error")return e(i.error);throw new Y("Invalid Result JSON")}S.fromJSON=g})(h||(h={}));var z=class{constructor(e){this.value=e}isOk(){return!0}isError(){return!this.isOk()}match(e){return e.Ok(this.value)}map(e){return h.Ok(e(this.value))}mapOr(e,t){return t(this.value)}mapOrElse(e,t){return t(this.value)}mapError(e){return this}and(e){return e}andThen(e){return e(this.value)}or(e){return this}orElse(e){return this}tap(e){return e(Object.freeze(structuredClone(this.value))),this}tapError(e){return this}ok(){return d.Some(this.value)}unwrap(){return this.value}unwrapError(){throw new Y("Cannot unwrapError an Ok")}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}toJSON(){return{__orf_type__:"Result",tag:"Ok",value:this.value}}},P=class{constructor(e){this.error=e}isOk(){return!1}isError(){return!this.isOk()}match(e){return e.Error(this.error)}map(e){return this}mapOr(e,t){return e}mapOrElse(e,t){return e()}mapError(e){return h.Error(e(this.error))}and(e){return this}andThen(e){return this}or(e){return e}orElse(e){return e(this.error)}tap(e){return this}tapError(e){return e(Object.freeze(structuredClone(this.error))),this}ok(){return d.None()}unwrap(){throw this.error}unwrapError(){return this.error}unwrapOr(e){return e}unwrapOrElse(e){return e(this.error)}toJSON(){return{__orf_type__:"Result",tag:"Error",error:this.error}}};var d;(k=>{function u(c){return Object.freeze(new q(c))}k.Some=u;function e(){return ie}k.None=e;function t(c){return c instanceof q||c instanceof B}k.isOption=t;function n(c){return c?u(c):e()}k.from=n;function l(c){if(c.__orf_type__!=="Option"&&!("tag"in c))throw new Error("Invalid Option JSON");if(c.tag==="Some")return u(c.value);if(c.tag==="None")return e();throw new Error("Invalid Option JSON")}k.fromJSON=l})(d||(d={}));var q=class{constructor(e){this.value=e}isSome(){return!0}isNone(){return!this.isSome()}match(e){return e.Some(this.value)}map(e){return d.Some(e(this.value))}mapOr(e,t){return t(this.value)}mapOrElse(e,t){return t(this.value)}and(e){return e}andThen(e){return e(this.value)}or(e){return this}orElse(e){return this}tap(e){return e(Object.freeze(structuredClone(this.value))),this}unwrap(){return this.value}unwrapOr(e){return this.value}unwrapOrElse(e){return this.value}okOr(e){return h.Ok(this.value)}okOrElse(e){return h.Ok(this.value)}toJSON(){return{__orf_type__:"Option",tag:"Some",value:this.value}}},B=class{isSome(){return!1}isNone(){return!this.isSome()}match(e){return e.None()}map(e){return this}mapOr(e,t){return e}mapOrElse(e,t){return e()}and(e){return this}andThen(e){return this}or(e){return e}orElse(e){return e()}tap(e){return this}unwrap(){throw new Error("Cannot unwrap None")}unwrapOr(e){return e}unwrapOrElse(e){return e()}okOr(e){return h.Error(e)}okOrElse(e){return h.Error(e())}toJSON(){return{__orf_type__:"Option",tag:"None"}}},ie=Object.freeze(new B);var v;(V=>{function u(o){return new C({tag:"completed",value:o})}V.value=u;function e(o){return new J({tag:"completed",value:h.Ok(o)})}V.success=e;function t(o){return new J({tag:"completed",value:h.Error(o)})}V.fail=t;function n(o){return o instanceof C}V.isFuture=n;function l(o){return o instanceof J}V.isFallibleFuture=l;function k(o){return o instanceof J?o:o instanceof Promise?V.makeFallible((p,U)=>{o.then(p).catch(U)}):o.match({Ok:p=>e(p),Error:p=>t(p)})}V.fromFallible=k;function c(o,p){return new C({tag:"pending",execute:o},p)}V.make=c;function g(o){return new C({tag:"pending",execute:o},{lazy:!0})}V.lazy=g;function S(o,p){return new J({tag:"pending",execute:o},p)}V.makeFallible=S;function i(o){return new J({tag:"pending",execute:o},{lazy:!0})}V.lazyFallible=i;function F(o){return new C({tag:"pending",execute:p=>{let U=setTimeout(p,o);return()=>{clearTimeout(U)}}})}V.wait=F;function O(o){if(!o.some(V.isFallibleFuture)){let w=V.make(_=>{let E=new Array(o.length),R=0;return o.forEach((f,x)=>{f.onResolved(m=>{E[x]=m,R+=1,R===o.length&&_(E)})}),()=>o.forEach(f=>f.cancel())});return o.forEach(_=>_.onCancelled(w.cancel.bind(w))),w}let U=V.makeFallible((w,_)=>{let E=new Array(o.length),R=0;for(let f=0;f<o.length;++f){let x=o[f];V.isFuture(x)&&(x=x.neverError()),x.onResolved(m=>{E[f]=m,R+=1,R===o.length&&h.all(E).match({Ok:w,Error:_})})}return()=>o.forEach(f=>f.cancel())});return o.forEach(w=>w.onCancelled(U.cancel.bind(U))),U}V.all=O;function b(o){let p=V.make(U=>{let w=new Array(o.length),_=0;return o.forEach((E,R)=>{E.onResolved(f=>{w[R]=f,_+=1,_===o.length&&U(w)})}),()=>o.forEach(E=>E.cancel())});return o.forEach(U=>U.onCancelled(p.cancel.bind(p))),p}V.allResolved=b;function ce(o){let p=Object.values(o),U=p.length;if(!p.some(V.isFallibleFuture)){let E=V.make(R=>{let f={},x=0;for(let m in o)o[m].onResolved(Q=>{f[m]=Q,x+=1,x===U&&R(f)});return()=>{for(let m of p)m.cancel()}});for(let R of p)R.onCancelled(E.cancel.bind(E));return E}let _=V.makeFallible((E,R)=>{let f={},x=0;for(let m in o){let K=o[m];V.isFuture(K)&&(K=K.neverError()),K.onResolved(Q=>{f[m]=Q,x+=1,x===U&&h.allFromDict(f).match({Ok:E,Error:R})})}return()=>{for(let m of p)m.cancel()}});for(let E of p)E.onCancelled(_.cancel.bind(_));return _}V.allFromDict=ce})(v||(v={}));var s,G,$,C=class{constructor(e,t){N(this,G);N(this,s,void 0);y(this,s,e),t!=null&&t.lazy||this.then()}onResolved(e){var t;r(this,s).tag==="pending"?(r(this,s).resolve_callbacks=(t=r(this,s).resolve_callbacks)!=null?t:[],r(this,s).resolve_callbacks.push(e)):r(this,s).tag==="completed"&&e(r(this,s).value)}onCancelled(e){var t;r(this,s).tag==="pending"?(r(this,s).cancel_callbacks=(t=r(this,s).cancel_callbacks)!=null?t:[],r(this,s).cancel_callbacks.push(e)):r(this,s).tag==="cancelled"&&e()}cancel(){if(r(this,s).tag==="pending"){let{cancel:e,cancel_callbacks:t}=r(this,s);y(this,s,{tag:"cancelled"}),e==null||e(),t==null||t.forEach(n=>n())}}then(e){if(r(this,s).tag==="pending"&&r(this,s).execute){let t=r(this,s).execute(D(this,G,$).bind(this));r(this,s).execute=null,t&&(r(this,s).cancel=t)}return e&&(this.onResolved(t=>e(d.Some(t))),this.onCancelled(()=>e(d.None()))),this}map(e){let t=v.make(n=>(this.onResolved(l=>{n(e(l))}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}tap(e){return this.onResolved(e),this}neverError(){let e=v.makeFallible((t,n)=>(this.onResolved(t),this.cancel.bind(this)));return this.onCancelled(e.cancel.bind(e)),e}unwrap(){let e=new A({tag:"pending",execute:t=>{this.onResolved(t)}});return this.onCancelled(e.cancel.bind(e)),e}unwrapOr(e){return new A({tag:"pending",execute:n=>(this.onResolved(l=>{n(l)}),this.onCancelled(()=>{n(e)}),()=>{n(e)})})}unwrapOrElse(e){return new A({tag:"pending",execute:n=>(this.onResolved(l=>{n(l)}),this.onCancelled(()=>{n(e())}),()=>{n(e())})})}};s=new WeakMap,G=new WeakSet,$=function(e){if(r(this,s).tag==="pending"){let{resolve_callbacks:t}=r(this,s);y(this,s,{tag:"completed",value:e}),t==null||t.forEach(n=>n(e))}};var a,H,j,L,ee,J=class{constructor(e,t){N(this,H);N(this,L);N(this,a,void 0);y(this,a,e),t!=null&&t.lazy||this.then()}onResolved(e){var t;r(this,a).tag==="pending"?(r(this,a).resolve_callbacks=(t=r(this,a).resolve_callbacks)!=null?t:[],r(this,a).resolve_callbacks.push(e)):r(this,a).tag==="completed"&&e(r(this,a).value)}onSucceeded(e){this.onResolved(t=>{t.match({Ok:e,Error:()=>{}})})}onFailed(e){this.onResolved(t=>{t.match({Ok:()=>{},Error:e})})}onCancelled(e){var t;r(this,a).tag==="pending"?(r(this,a).cancel_callbacks=(t=r(this,a).cancel_callbacks)!=null?t:[],r(this,a).cancel_callbacks.push(e)):r(this,a).tag==="cancelled"&&e()}cancel(){if(r(this,a).tag==="pending"){let{cancel:e,cancel_callbacks:t}=r(this,a);y(this,a,{tag:"cancelled"}),e==null||e(),t==null||t.forEach(n=>n())}}then(e){if(r(this,a).tag==="pending"&&r(this,a).execute){let t=r(this,a).execute(D(this,H,j).bind(this),D(this,L,ee).bind(this));r(this,a).execute=null,t&&(r(this,a).cancel=t)}return e&&(this.onResolved(t=>e(d.Some(t))),this.onCancelled(()=>e(d.None()))),this}map(e){let t=v.makeFallible((n,l)=>(this.onResolved(k=>{k.match({Ok:c=>{n(e(c))},Error:l})}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}mapError(e){let t=v.makeFallible((n,l)=>(this.onResolved(k=>{k.match({Ok:n,Error:c=>{l(e(c))}})}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}andThen(e){let t=v.makeFallible((n,l)=>(this.onResolved(k=>{k.match({Ok:c=>{let g=v.fromFallible(e(c));g.onSucceeded(n),g.onFailed(l)},Error:l})}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}orElse(e){let t=v.makeFallible((n,l)=>(this.onResolved(k=>{k.match({Ok:n,Error:c=>{let g=v.fromFallible(e(c));g.onSucceeded(n),g.onFailed(l)}})}),this.cancel.bind(this)));return this.onCancelled(t.cancel.bind(t)),t}tap(e){return this.onSucceeded(e),this}tapError(e){return this.onFailed(e),this}ok(){let e=v.make(t=>(this.onSucceeded(n=>t(d.Some(n))),this.onFailed(()=>t(d.None())),this.cancel.bind(this)));return this.onCancelled(e.cancel.bind(e)),e}unwrap(){let e=new A({tag:"pending",execute:t=>{this.onResolved(t)}});return this.onCancelled(e.cancel.bind(e)),e}unwrapOr(e){return new A({tag:"pending",execute:n=>(this.onResolved(n),this.onCancelled(()=>{n(e)}),()=>{n(e)})})}unwrapOrElse(e){return new A({tag:"pending",execute:n=>(this.onResolved(n),this.onCancelled(()=>{n(e())}),()=>{n(e())})})}match(e){let t=new A({tag:"pending",execute:n=>{this.onResolved(l=>{n(l.match(e))})}});return this.onCancelled(t.cancel.bind(t)),t}};a=new WeakMap,H=new WeakSet,j=function(e){if(r(this,a).tag==="pending"){let{resolve_callbacks:t}=r(this,a),n=h.Ok(e);y(this,a,{tag:"completed",value:n}),t==null||t.forEach(l=>l(n))}},L=new WeakSet,ee=function(e){if(r(this,a).tag==="pending"){let{resolve_callbacks:t}=r(this,a),n=h.Error(e);y(this,a,{tag:"completed",value:n}),t==null||t.forEach(l=>l(n))}};var T,I,M,te,A=class{constructor(e){N(this,M);N(this,T,void 0);N(this,I,void 0);if(y(this,T,e),r(this,T).tag==="pending"&&r(this,T).execute){let t=r(this,T).execute(D(this,M,te).bind(this));r(this,T).execute=null,t&&!r(this,I)&&y(this,I,t)}}onResolved(e){var t;r(this,T).tag==="pending"?(r(this,T).resolve_callbacks=(t=r(this,T).resolve_callbacks)!=null?t:[],r(this,T).resolve_callbacks.push(e)):r(this,T).tag==="completed"&&e(r(this,T).value)}onCancelled(e){r(this,T).tag==="pending"&&!r(this,I)?y(this,I,e):r(this,T).tag==="cancelled"&&!r(this,I)&&e(new Error("Cannot cancel UnwrappedFuture"))}cancel(){r(this,T).tag==="pending"&&(r(this,I)?(r(this,I).call(this,new Error("Cannot cancel UnwrappedFuture")),r(this,T).tag==="pending"&&y(this,T,{tag:"cancelled"})):y(this,T,{tag:"cancelled"}))}then(e,t){return e&&this.onResolved(e),t&&this.onCancelled(t),this}};T=new WeakMap,I=new WeakMap,M=new WeakSet,te=function(e){if(r(this,T).tag==="pending"){let{resolve_callbacks:t}=r(this,T);y(this,T,{tag:"completed",value:e}),t==null||t.forEach(n=>n(e))}};0&&(module.exports={Future,Option,Result}); |
{ | ||
"name": "@nobrayner/orf", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "Option. Result. Future", | ||
@@ -5,0 +5,0 @@ "sideEffect": false, |
Sorry, the diff of this file is not supported yet
73727
1568