f-box-core
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -1,1 +0,1 @@ | ||
(function(f,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(f=typeof globalThis<"u"?globalThis:f||self,y(f["f-box-core"]={}))})(this,function(f){"use strict";const y=t=>{const e=s=>y(s(t)),n=function(s){const a=this.getValue();return s.map(l=>a(l))},o=s=>s(t);return{isBox:!0,map:e,apply:n,flatMap:o,getValue:()=>t,"<$>":e,"<*>":n,">>=":o}},O=t=>(t==null?void 0:t.isBox)===!0;function I(t){const e=t();function n(o){const{value:c,done:s}=e.next(o);return s?H.pack(c):c[">>="](n)}return n(void 0)}const H={do:I,pack:y,isBox:O},E=t=>{let e=t;const n=new Map,o=[],c=()=>{n.forEach(i=>i(e))},s=()=>e,a=i=>{typeof i=="function"?e=i(e):e=i,c()},l=i=>{const u=E(i(e)),h=b(V=>{u.setValue(i(V))});return u.detachHandlers.push(()=>N(h)),u},r=i=>{let u=i(e);const h=E(u.getValue()),v=b(_=>{u.detach(),u=i(_),h.setValue(u.getValue());const et=u.subscribe(nt=>{h.setValue(nt)});h.detachHandlers.push(()=>u.unsubscribe(et))});h.detachHandlers.push(()=>N(v));const tt=u.subscribe(_=>{h.setValue(_)});return h.detachHandlers.push(()=>u.unsubscribe(tt)),h},d=function(i){const u=E(this.getValue()(i.getValue())),h=()=>u.setValue(this.getValue()(i.getValue())),V=[this.subscribe(h),i.subscribe(h)];return u.detachHandlers.push(()=>{this.unsubscribe(V[0]),i.unsubscribe(V[1])}),u},b=i=>{const u=Math.random().toString(36).substr(2,9);return n.set(u,i),u},N=i=>{n.delete(i)};return{isRBox:!0,getValue:s,setValue:a,map:l,flatMap:r,apply:d,"<$>":l,">>=":r,"<*>":d,subscribe:b,unsubscribe:N,unsubscribeAll:()=>{n.clear()},detach:()=>{o.forEach(i=>i()),o.length=0},detachHandlers:o}},P=t=>e=>{t.setValue(e)},q=t=>t&&typeof t=="object"&&t.isRBox===!0;function w(t){const e=t();function n(o){const{value:c,done:s}=e.next(o);return s?D.pack(c):c[">>="](n)}return n(void 0)}const D={do:w,pack:E,set:P,isRBox:q},g={isMaybe:!0,isJust:!1,isNothing:!0,map:()=>g,apply:()=>g,flatMap:()=>g,getValue:()=>null,orElse:t=>t,getOrElse:t=>t,match:(t,e)=>e(),"<$>":()=>g,"<*>":()=>g,">>=":()=>g,"<?>":t=>t,"<|>":t=>t},J=t=>x(t)?B():M(t),B=()=>g,M=t=>{const e=r=>J(r(t)),n=function(r){if(R(this)||R(r))return B();const d=this.getValue();return r.map(b=>d(b))},o=r=>r(t),c=()=>t,s=r=>M(t),a=r=>t;return{isMaybe:!0,isJust:!0,isNothing:!1,map:e,apply:n,flatMap:o,getValue:c,orElse:s,getOrElse:a,match:(r,d)=>r(t),"<$>":e,"<*>":n,">>=":o,"<?>":s,"<|>":a}},x=t=>t==null,$=t=>typeof t!="object"||x(t)||!("isMaybe"in t)?!1:t.isMaybe===!0,z=t=>$(t)&&t.isJust,R=t=>$(t)&&t.isNothing;function F(t){const e=t();function n(o){const{value:c,done:s}=e.next(o);return s?K.pack(c):c[">>="](n)}return n(void 0)}const K={do:F,pack:J,just:M,nothing:B,isNone:x,isMaybe:$,isNothing:R,isJust:z},p=t=>({isEither:!0,isLeft:!0,isRight:!1,map:()=>p(t),apply:()=>p(t),flatMap:()=>p(t),getValue:()=>t,orElse:e=>e,getOrElse:e=>e,match:(e,n)=>e(t),"<$>":()=>p(t),"<*>":()=>p(t),">>=":()=>p(t),"<?>":e=>e,"<|>":e=>e}),k=t=>{const e=r=>k(r(t)),n=function(r){if(j(this))return p(this.getValue());if(j(r))return p(r.getValue());const d=this.getValue();return r.map(b=>d(b))},o=r=>r(t),c=()=>t,s=r=>k(t),a=r=>t;return{isEither:!0,isLeft:!1,isRight:!0,map:e,apply:n,flatMap:o,getValue:c,orElse:s,getOrElse:a,match:(r,d)=>d(t),"<$>":e,"<*>":n,">>=":o,"<?>":s,"<|>":a}},G=k,L=t=>t==null,T=t=>typeof t!="object"||L(t)||!("isEither"in t)?!1:t.isEither===!0,j=t=>T(t)&&t.isLeft,Q=t=>T(t)&&t.isRight;function U(t){const e=t();function n(o){const{value:c,done:s}=e.next(o);return s?S.right(c):c[">>="](n)}return n(void 0)}const S={do:U,pack:G,right:k,left:p,isNone:L,isEither:T,isLeft:j,isRight:Q},m=t=>{const e=s=>m(()=>t().then(s)),n=s=>m(()=>t().then(a=>s(a).run())),o=function(s){return m(()=>this.run().then(a=>typeof a!="function"?Promise.reject(new TypeError("fn is not a function")):s.run().then(l=>a(l))))};return{isTask:!0,map:e,flatMap:n,apply:o,run:t,"<$>":e,"<*>":o,">>=":n}},A=(t,e)=>m(()=>Promise.resolve().then(()=>t()).catch(n=>Promise.resolve(e(n)))),W=t=>A(t,e=>Promise.reject(e)),X=t=>m(()=>Promise.resolve(t)),Y=t=>(t==null?void 0:t.isTask)===!0;function Z(t){const e=t();function n(o){const{value:c,done:s}=e.next(o);return s?C.pack(c):c[">>="](n)}return n(void 0)}const C={do:Z,from:m,pack:X,tryCatch:A,tryTask:W,isTask:Y};f.Box=H,f.Either=S,f.Maybe=K,f.RBox=D,f.Task=C,f.isBox=O,f.set=P,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}); | ||
(function(f,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(f=typeof globalThis<"u"?globalThis:f||self,y(f["f-box-core"]={}))})(this,function(f){"use strict";const y=t=>{const e=o=>y(o(t)),s=function(o){const a=this.getValue();return o.map(l=>a(l))},r=o=>o(t);return{isBox:!0,map:e,apply:s,flatMap:r,getValue:()=>t,"<$>":e,"<*>":s,">>=":r}},K=t=>(t==null?void 0:t.isBox)===!0;function I(t){const e=t();function s(r){const{value:n,done:o}=e.next(r);return o?E.isBox(n)?n:E.pack(n):n[">>="](s)}return s(void 0)}const E={do:I,pack:y,isBox:K},k=t=>{let e=t;const s=new Map,r=[],n=()=>{s.forEach(c=>c(e))},o=()=>e,a=c=>{typeof c=="function"?e=c(e):e=c,n()},l=c=>{const u=k(c(e)),h=g(V=>{u.setValue(c(V))});return u.detachHandlers.push(()=>D(h)),u},i=c=>{let u=c(e);const h=k(u.getValue()),v=g(J=>{u.detach(),u=c(J),h.setValue(u.getValue());const et=u.subscribe(st=>{h.setValue(st)});h.detachHandlers.push(()=>u.unsubscribe(et))});h.detachHandlers.push(()=>D(v));const tt=u.subscribe(J=>{h.setValue(J)});return h.detachHandlers.push(()=>u.unsubscribe(tt)),h},d=function(c){const u=k(this.getValue()(c.getValue())),h=()=>u.setValue(this.getValue()(c.getValue())),V=[this.subscribe(h),c.subscribe(h)];return u.detachHandlers.push(()=>{this.unsubscribe(V[0]),c.unsubscribe(V[1])}),u},g=c=>{const u=Math.random().toString(36).substr(2,9);return s.set(u,c),u},D=c=>{s.delete(c)};return{isRBox:!0,getValue:o,setValue:a,map:l,flatMap:i,apply:d,"<$>":l,">>=":i,"<*>":d,subscribe:g,unsubscribe:D,unsubscribeAll:()=>{s.clear()},detach:()=>{r.forEach(c=>c()),r.length=0},detachHandlers:r}},L=t=>e=>{t.setValue(e)},q=t=>t&&typeof t=="object"&&t.isRBox===!0;function w(t){const e=t();function s(r){const{value:n,done:o}=e.next(r);return o?M.isRBox(n)?n:M.pack(n):n[">>="](s)}return s(void 0)}const M={do:w,pack:k,set:L,isRBox:q},b={isMaybe:!0,isJust:!1,isNothing:!0,map:()=>b,apply:()=>b,flatMap:()=>b,getValue:()=>null,orElse:t=>t,getOrElse:t=>t,match:(t,e)=>e(),"<$>":()=>b,"<*>":()=>b,">>=":()=>b,"<?>":t=>t,"<|>":t=>t},S=t=>R(t)?x():$(t),x=()=>b,$=t=>{const e=i=>S(i(t)),s=function(i){if(j(this)||j(i))return x();const d=this.getValue();return i.map(g=>d(g))},r=i=>i(t),n=()=>t,o=i=>$(t),a=i=>t;return{isMaybe:!0,isJust:!0,isNothing:!1,map:e,apply:s,flatMap:r,getValue:n,orElse:o,getOrElse:a,match:(i,d)=>i(t),"<$>":e,"<*>":s,">>=":r,"<?>":o,"<|>":a}},R=t=>t==null,T=t=>typeof t!="object"||R(t)||!("isMaybe"in t)?!1:t.isMaybe===!0,z=t=>T(t)&&t.isJust,j=t=>T(t)&&t.isNothing;function F(t){const e=t();function s(r){const{value:n,done:o}=e.next(r);return o?N.isMaybe(n)?n:N.pack(n):n[">>="](s)}return s(void 0)}const N={do:F,pack:S,just:$,nothing:x,isNone:R,isMaybe:T,isNothing:j,isJust:z},p=t=>({isEither:!0,isLeft:!0,isRight:!1,map:()=>p(t),apply:()=>p(t),flatMap:()=>p(t),getValue:()=>t,orElse:e=>e,getOrElse:e=>e,match:(e,s)=>e(t),"<$>":()=>p(t),"<*>":()=>p(t),">>=":()=>p(t),"<?>":e=>e,"<|>":e=>e}),B=t=>{const e=i=>B(i(t)),s=function(i){if(O(this))return p(this.getValue());if(O(i))return p(i.getValue());const d=this.getValue();return i.map(g=>d(g))},r=i=>i(t),n=()=>t,o=i=>B(t),a=i=>t;return{isEither:!0,isLeft:!1,isRight:!0,map:e,apply:s,flatMap:r,getValue:n,orElse:o,getOrElse:a,match:(i,d)=>d(t),"<$>":e,"<*>":s,">>=":r,"<?>":o,"<|>":a}},G=B,A=t=>t==null,_=t=>typeof t!="object"||A(t)||!("isEither"in t)?!1:t.isEither===!0,O=t=>_(t)&&t.isLeft,Q=t=>_(t)&&t.isRight;function U(t){const e=t();function s(r){const{value:n,done:o}=e.next(r);return o?H.isEither(n)?n:H.pack(n):n[">>="](s)}return s(void 0)}const H={do:U,pack:G,right:B,left:p,isNone:A,isEither:_,isLeft:O,isRight:Q},m=t=>{const e=o=>m(()=>t().then(o)),s=o=>m(()=>t().then(a=>o(a).run())),r=function(o){return m(()=>this.run().then(a=>typeof a!="function"?Promise.reject(new TypeError("fn is not a function")):o.run().then(l=>a(l))))};return{isTask:!0,map:e,flatMap:s,apply:r,run:t,"<$>":e,"<*>":r,">>=":s}},C=(t,e)=>m(()=>Promise.resolve().then(()=>t()).catch(s=>Promise.resolve(e(s)))),W=t=>C(t,e=>Promise.reject(e)),X=t=>m(()=>Promise.resolve(t)),Y=t=>(t==null?void 0:t.isTask)===!0;function Z(t){const e=t();function s(r){const{value:n,done:o}=e.next(r);return o?P.isTask(n)?n:P.pack(n):n[">>="](s)}return s(void 0)}const P={do:Z,from:m,pack:X,tryCatch:C,tryTask:W,isTask:Y};f.Box=E,f.Either=H,f.Maybe=N,f.RBox=M,f.Task=P,f.isBox=K,f.set=L,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}); |
@@ -72,3 +72,3 @@ /** | ||
*/ | ||
declare function Do<T, U>(generatorFunc: () => Generator<Box<T>, U, T>): Box<U>; | ||
declare function Do<T, U>(generatorFunc: () => Generator<Box<T>, U | Box<U>, T>): Box<U>; | ||
/** | ||
@@ -75,0 +75,0 @@ * Box utility object containing helpers like `pack` and `isBox`. |
@@ -200,3 +200,3 @@ type None = null | undefined | void; | ||
*/ | ||
declare function Do<L, R, U>(generatorFunc: () => Generator<Either<L, R>, U, R>): Either<L, U>; | ||
declare function Do<L, R, U>(generatorFunc: () => Generator<Either<L, R>, U | Either<L, U>, R>): Either<L, U>; | ||
/** | ||
@@ -203,0 +203,0 @@ * A utility object containing constructors and helpers for `Either`. |
@@ -206,3 +206,3 @@ /** | ||
*/ | ||
declare function Do<T, U>(generatorFunc: () => Generator<Maybe<T>, U, T>): Maybe<U>; | ||
declare function Do<T, U>(generatorFunc: () => Generator<Maybe<T>, U | Maybe<U>, T>): Maybe<U>; | ||
/** | ||
@@ -209,0 +209,0 @@ * A utility object containing constructors and helpers for `Maybe`. |
@@ -113,3 +113,3 @@ /** | ||
*/ | ||
declare function Do<T, U>(generatorFunc: () => Generator<RBox<T>, U, T>): RBox<U>; | ||
declare function Do<T, U>(generatorFunc: () => Generator<RBox<T>, U | RBox<U>, T>): RBox<U>; | ||
/** | ||
@@ -116,0 +116,0 @@ * RBox utility object containing helpers like `pack`, `set`, and `isRBox`. |
@@ -64,3 +64,3 @@ /** | ||
*/ | ||
declare function Do<T, U>(generatorFunc: () => Generator<Task<T>, U, T>): Task<U>; | ||
declare function Do<T, U>(generatorFunc: () => Generator<Task<T>, U | Task<U>, T>): Task<U>; | ||
/** | ||
@@ -67,0 +67,0 @@ * Task utility object containing constructors and helper functions. |
{ | ||
"name": "f-box-core", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Put your data in a box, and suddenly it's easier to handle, transform, and use however you need.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
59091