@tdreyno/pretty-please
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -96,4 +96,2 @@ 'use strict'; | ||
constructor(computation) { | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
this.andThen = this.chain; | ||
this.fork = computation; | ||
@@ -336,3 +334,2 @@ } | ||
* Chain a task to run after a previous task has succeeded. | ||
* @alias andThen | ||
* @param fn Takes a successful result and returns a new task. | ||
@@ -674,3 +671,3 @@ * @param task The task which will chain to the next one on success. | ||
function swap(task) { | ||
return new Task((reject, resolve) => task.fork(resolve, reject)); | ||
return new Task((reject, resolve) => task.fork(e => resolve(e), s => reject(s))); | ||
} | ||
@@ -677,0 +674,0 @@ /** |
@@ -9,4 +9,2 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-explicit-any, @typescript-eslint/no-use-before-define */ | ||
constructor(computation) { | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
this.andThen = this.chain; | ||
this.fork = computation; | ||
@@ -226,3 +224,2 @@ } | ||
* Chain a task to run after a previous task has succeeded. | ||
* @alias andThen | ||
* @param fn Takes a successful result and returns a new task. | ||
@@ -234,3 +231,2 @@ * @param task The task which will chain to the next one on success. | ||
} | ||
export const andThen = chain; | ||
/** | ||
@@ -511,3 +507,3 @@ * If a function returns a Promise instead of a Task, automatically | ||
export function swap(task) { | ||
return new Task((reject, resolve) => task.fork(resolve, reject)); | ||
return new Task((reject, resolve) => task.fork(e => resolve(e), s => reject(s))); | ||
} | ||
@@ -514,0 +510,0 @@ /** |
@@ -35,3 +35,2 @@ export declare type Reject<E> = (error: E) => void; | ||
fork: Fork<E, S>; | ||
andThen: <S2>(fn: (result: S) => Task<E, S2> | Promise<S2>) => Task<E, S2>; | ||
constructor(computation: Fork<E, S>); | ||
@@ -47,3 +46,3 @@ /** | ||
toPromise(): Promise<S>; | ||
swap(): Task<S, E>; | ||
swap<E2 extends E, S2 extends S>(): Task<S2, E2>; | ||
map<S2>(fn: (result: S) => S2): Task<E, S2>; | ||
@@ -130,3 +129,2 @@ forward<S2>(value: S2): Task<E, S2>; | ||
* Chain a task to run after a previous task has succeeded. | ||
* @alias andThen | ||
* @param fn Takes a successful result and returns a new task. | ||
@@ -136,3 +134,2 @@ * @param task The task which will chain to the next one on success. | ||
export declare function chain<E, S, S2>(fn: (result: S) => Task<E, S2> | Promise<S2>, task: Task<E, S>): Task<E, S2>; | ||
export declare const andThen: typeof chain; | ||
/** | ||
@@ -232,3 +229,3 @@ * When forked, run a function which can check whether the task has already succeeded. | ||
*/ | ||
export declare function swap<E, S>(task: Task<E, S>): Task<S, E>; | ||
export declare function swap<E, S, E2 extends E, S2 extends S>(task: Task<E, S>): Task<S2, E2>; | ||
/** | ||
@@ -235,0 +232,0 @@ * Given a task, map the successful value to a Task. |
@@ -78,4 +78,2 @@ function initialize() { | ||
constructor(computation) { | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
this.andThen = this.chain; | ||
this.fork = computation; | ||
@@ -286,3 +284,2 @@ } | ||
* Chain a task to run after a previous task has succeeded. | ||
* @alias andThen | ||
* @param fn Takes a successful result and returns a new task. | ||
@@ -568,3 +565,3 @@ * @param task The task which will chain to the next one on success. | ||
function swap(task) { | ||
return new Task((reject, resolve) => task.fork(resolve, reject)); | ||
return new Task((reject, resolve) => task.fork(e => resolve(e), s => reject(s))); | ||
} | ||
@@ -571,0 +568,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
var t=Object.freeze({__proto__:null,initialize:function(){return{type:"Initialized"}},pending:function(){return{type:"Pending"}},succeed:function(t){return{type:"Success",result:t}},fail:function(t){return{type:"Failure",error:t}},fold:function(t,n,r,e,i){switch(i.type){case"Initialized":return t();case"Pending":return n();case"Failure":return r(i.error);case"Success":return e(i.result)}}});function n(t,n=0){return Array(t-n).fill(void 0).map((t,r)=>n+r)}function r(t){return(n,r,e,i)=>e===i.length-1?t(i):n}function e(t){return()=>t}function i(t){return t}function u(t){return(n,r,e)=>{const[i,u]=t(r,e);return n[i]=u,n}}function s(t,n,r={}){return n.reduce(u(t),r)}function c(t,[n,r]){return t[n]=r,t}class o{constructor(t){this.andThen=this.chain,this.fork=t}then(t,n){return this.toPromise().then(t,n)}chain(t){return p(t,this)}succeedIf(t){return function(t,n){return new o((r,e)=>{const i=t();i?e(i):n.fork(r,e)})}(t,this)}onlyOnce(){return function(t){let n,r,e="initialized",i=0;const u={};function s(t,n){const r=i++;u[r]={reject:t,resolve:n}}function c(t){e="failure",r=t,Object.keys(u).forEach(n=>{u[n].reject(t),delete u[n]})}function f(t){e="success",n=t,Object.keys(u).forEach(n=>{u[n].resolve(t),delete u[n]})}return new o((i,u)=>{switch(e){case"success":u(n);break;case"failure":i(r);break;case"pending":s(i,u);break;case"initialized":e="pending",s(i,u),t.fork(c,f)}})}(this)}toPromise(){return t=this,new Promise((n,r)=>t.fork(r,n));var t}swap(){return t=this,new o((n,r)=>t.fork(r,n));var t}map(t){return I(t,this)}forward(t){return I(e(t),this)}tap(t){return function(t,n){return I(n=>(t(n),n),n)}(t,this)}tapChain(t){return function(t,n){return p(n=>m(t(n)).forward(n),n)}(t,this)}mapError(t){return S(t,this)}mapBoth(t,n){return function(t,n,r){return S(t,I(n,r))}(t,n,this)}fold(t,n){return function(t,n,r){return new o((e,i)=>r.fork(n=>i(t(n)),t=>i(n(t))))}(t,n,this)}orElse(t){return function(t,n){return new o((r,e)=>n.fork(n=>m(t(n)).fork(r,e),e))}(t,this)}ap(t){return j(this,t)}wait(t){return function(t,n){return new o((r,e)=>{setTimeout(()=>n.fork(r,e),t)})}(t,this)}retryIn(t){return function(t,n){return n.orElse(()=>n.wait(t))}(t,this)}retryWithExponentialBackoff(t,r){return function(t,r,e){return n(r).reduce((n,r)=>n.retryIn(t*2**r),e)}(t,r,this)}flatten(){return k(this)}}o.fail=d,o.succeed=a,o.empty=function(){return l(void 0)},o.failIn=function(t,n){return new o(r=>setTimeout(()=>r(n),t))},o.succeedIn=function(t,n){return new o((r,e)=>setTimeout(()=>e(n),t))},o.of=a,o.all=function(t){return 0===t.length?l([]):new o((n,r)=>{let e=!1,i=t.length;const u=[];return t.map((t,s)=>m(t).fork(t=>{e||(e=!0,n(t))},t=>{e||(i-=1,u[s]=t,0===i&&r(u))}))})},o.sequence=function(t){return 0===t.length?l([]):t.reduce((t,n)=>p(t=>I(n=>[...t,n],m(n)),t),a([]))},o.firstSuccess=function(t){return 0===t.length?d([]):new o((n,r)=>{let e=!1,i=t.length;const u=[];return t.map(t=>m(t).fork(t=>{e||(i-=1,u.push(t),0===i&&n(u))},t=>{e||(e=!0,r(t))}))})},o.never=function(){return new o(()=>{})},o.fromPromise=y,o.fromLazyPromise=function(t){return w(t).chain(y)},o.race=function(t){return new o((n,r)=>{let e=!1;return t.map(t=>m(t).fork(t=>{e||(e=!0,n(t))},t=>{e||(e=!0,r(t))}))})},o.external=h,o.emitter=function(t){const n=h();return[n,(...r)=>{try{n.resolve(t(...r))}catch(t){n.reject(t)}}]},o.succeedBy=w,o.ap=j,o.map2=P,o.map3=function(t,n,r,e){return o.of(t).ap(n).ap(r).ap(e)},o.map4=function(t,n,r,e,i){return o.of(t).ap(n).ap(r).ap(e).ap(i)},o.loop=b,o.reduce=function(t,n,r){return b(({remainingItems:n,currentResult:e})=>{if(0===n.length)return l(new g(e));const[i,...u]=n,s=r.length-u.length-1;return t(e,i,s,r).map(t=>new v({remainingItems:u,currentResult:t}))},{remainingItems:r,currentResult:n})},o.zip=function(t,n){return P(t=>n=>[t,n],t,n)},o.zipWith=function(t,n,r){return P(n=>r=>t(n,r),n,r)},o.flatten=k;class f extends o{constructor(){super((t,n)=>{switch(this.t){case"error":t(this.i);case"success":n(this.u);case"pending":this.s=t,this.o=n}}),this.t="pending"}reject(t){this.i=t,this.t="error",this.s&&this.s(t)}resolve(t){this.u=t,this.t="success",this.o&&this.o(t)}}function h(){return new f}function a(t){return new o((n,r)=>r(t))}const l=a;function w(t){return new o((n,r)=>{try{r(t())}catch(t){n(t)}})}function d(t){return new o(n=>n(t))}function p(t,n){return new o((r,e)=>n.fork(r,n=>m(t(n)).fork(r,e)))}function m(t){return t instanceof Promise?y(t):t}function y(t){return t instanceof Promise?new o((n,r)=>t.then(r,n)):l(t)}class g{constructor(t){this.value=t}}class v{constructor(t){this.value=t}}function b(t,n){return new o((r,e)=>{const i=n=>{t(n).fork(t=>{r(t)},t=>{t instanceof g&&e(t.value),t instanceof v&&i(t.value)})};i(n)})}function I(t,n){return new o((r,e)=>n.fork(r,n=>e(t(n))))}function P(t,n,r){return o.of(t).ap(n).ap(r)}function S(t,n){return new o((r,e)=>n.fork(n=>r(t(n)),e))}function j(t,n){return new o((r,e)=>{let i,u,s=!1,c=!1;const o=t=>n=>{c||(t(n),u&&s&&e(u(i)))},f=t=>{c||(c=!0,r(t))};m(t).fork(f,o(t=>{u=t})),m(n).fork(f,o(t=>{s=!0,i=t}))})}function k(t){return t.chain(i)}class z{constructor(){this.h=new Set,this.l="inactive",this.p=new Set}emit(t){return o.all(Array.from(this.h).map(n=>n(t)||o.empty()))}subscribe(t){return this.h.add(t),this.m(),()=>{this.h.delete(t),this.m()}}clear(){this.h.clear(),this.m()}onStatusChange(t){return this.p.add(t),()=>this.p.delete(t)}m(){const t=this.h.size>0?"active":"inactive";t!==this.l&&(this.l=t,Array.from(this.p).map(n=>n(t)))}}export{f as ExternalTask,g as LoopBreak,v as LoopContinue,t as RemoteData,z as Subscription,o as Task,e as constant,i as identity,s as mapToIndexedObject,c as pairsToIndexedObject,n as range,r as to,u as toIndexedObject}; | ||
var n=Object.freeze({__proto__:null,initialize:function(){return{type:"Initialized"}},pending:function(){return{type:"Pending"}},succeed:function(n){return{type:"Success",result:n}},fail:function(n){return{type:"Failure",error:n}},fold:function(n,t,r,e,i){switch(i.type){case"Initialized":return n();case"Pending":return t();case"Failure":return r(i.error);case"Success":return e(i.result)}}});function t(n,t=0){return Array(n-t).fill(void 0).map((n,r)=>t+r)}function r(n){return(t,r,e,i)=>e===i.length-1?n(i):t}function e(n){return()=>n}function i(n){return n}function u(n){return(t,r,e)=>{const[i,u]=n(r,e);return t[i]=u,t}}function s(n,t,r={}){return t.reduce(u(n),r)}function c(n,[t,r]){return n[t]=r,n}class o{constructor(n){this.fork=n}then(n,t){return this.toPromise().then(n,t)}chain(n){return p(n,this)}succeedIf(n){return function(n,t){return new o((r,e)=>{const i=n();i?e(i):t.fork(r,e)})}(n,this)}onlyOnce(){return function(n){let t,r,e="initialized",i=0;const u={};function s(n,t){const r=i++;u[r]={reject:n,resolve:t}}function c(n){e="failure",r=n,Object.keys(u).forEach(t=>{u[t].reject(n),delete u[t]})}function f(n){e="success",t=n,Object.keys(u).forEach(t=>{u[t].resolve(n),delete u[t]})}return new o((i,u)=>{switch(e){case"success":u(t);break;case"failure":i(r);break;case"pending":s(i,u);break;case"initialized":e="pending",s(i,u),n.fork(c,f)}})}(this)}toPromise(){return n=this,new Promise((t,r)=>n.fork(r,t));var n}swap(){return n=this,new o((t,r)=>n.fork(n=>r(n),n=>t(n)));var n}map(n){return I(n,this)}forward(n){return I(e(n),this)}tap(n){return function(n,t){return I(t=>(n(t),t),t)}(n,this)}tapChain(n){return function(n,t){return p(t=>m(n(t)).forward(t),t)}(n,this)}mapError(n){return S(n,this)}mapBoth(n,t){return function(n,t,r){return S(n,I(t,r))}(n,t,this)}fold(n,t){return function(n,t,r){return new o((e,i)=>r.fork(t=>i(n(t)),n=>i(t(n))))}(n,t,this)}orElse(n){return function(n,t){return new o((r,e)=>t.fork(t=>m(n(t)).fork(r,e),e))}(n,this)}ap(n){return j(this,n)}wait(n){return function(n,t){return new o((r,e)=>{setTimeout(()=>t.fork(r,e),n)})}(n,this)}retryIn(n){return function(n,t){return t.orElse(()=>t.wait(n))}(n,this)}retryWithExponentialBackoff(n,r){return function(n,r,e){return t(r).reduce((t,r)=>t.retryIn(n*2**r),e)}(n,r,this)}flatten(){return k(this)}}o.fail=d,o.succeed=h,o.empty=function(){return l(void 0)},o.failIn=function(n,t){return new o(r=>setTimeout(()=>r(t),n))},o.succeedIn=function(n,t){return new o((r,e)=>setTimeout(()=>e(t),n))},o.of=h,o.all=function(n){return 0===n.length?l([]):new o((t,r)=>{let e=!1,i=n.length;const u=[];return n.map((n,s)=>m(n).fork(n=>{e||(e=!0,t(n))},n=>{e||(i-=1,u[s]=n,0===i&&r(u))}))})},o.sequence=function(n){return 0===n.length?l([]):n.reduce((n,t)=>p(n=>I(t=>[...n,t],m(t)),n),h([]))},o.firstSuccess=function(n){return 0===n.length?d([]):new o((t,r)=>{let e=!1,i=n.length;const u=[];return n.map(n=>m(n).fork(n=>{e||(i-=1,u.push(n),0===i&&t(u))},n=>{e||(e=!0,r(n))}))})},o.never=function(){return new o(()=>{})},o.fromPromise=y,o.fromLazyPromise=function(n){return w(n).chain(y)},o.race=function(n){return new o((t,r)=>{let e=!1;return n.map(n=>m(n).fork(n=>{e||(e=!0,t(n))},n=>{e||(e=!0,r(n))}))})},o.external=a,o.emitter=function(n){const t=a();return[t,(...r)=>{try{t.resolve(n(...r))}catch(n){t.reject(n)}}]},o.succeedBy=w,o.ap=j,o.map2=P,o.map3=function(n,t,r,e){return o.of(n).ap(t).ap(r).ap(e)},o.map4=function(n,t,r,e,i){return o.of(n).ap(t).ap(r).ap(e).ap(i)},o.loop=b,o.reduce=function(n,t,r){return b(({remainingItems:t,currentResult:e})=>{if(0===t.length)return l(new g(e));const[i,...u]=t,s=r.length-u.length-1;return n(e,i,s,r).map(n=>new v({remainingItems:u,currentResult:n}))},{remainingItems:r,currentResult:t})},o.zip=function(n,t){return P(n=>t=>[n,t],n,t)},o.zipWith=function(n,t,r){return P(t=>r=>n(t,r),t,r)},o.flatten=k;class f extends o{constructor(){super((n,t)=>{switch(this.t){case"error":n(this.i);case"success":t(this.u);case"pending":this.s=n,this.o=t}}),this.t="pending"}reject(n){this.i=n,this.t="error",this.s&&this.s(n)}resolve(n){this.u=n,this.t="success",this.o&&this.o(n)}}function a(){return new f}function h(n){return new o((t,r)=>r(n))}const l=h;function w(n){return new o((t,r)=>{try{r(n())}catch(n){t(n)}})}function d(n){return new o(t=>t(n))}function p(n,t){return new o((r,e)=>t.fork(r,t=>m(n(t)).fork(r,e)))}function m(n){return n instanceof Promise?y(n):n}function y(n){return n instanceof Promise?new o((t,r)=>n.then(r,t)):l(n)}class g{constructor(n){this.value=n}}class v{constructor(n){this.value=n}}function b(n,t){return new o((r,e)=>{const i=t=>{n(t).fork(n=>{r(n)},n=>{n instanceof g&&e(n.value),n instanceof v&&i(n.value)})};i(t)})}function I(n,t){return new o((r,e)=>t.fork(r,t=>e(n(t))))}function P(n,t,r){return o.of(n).ap(t).ap(r)}function S(n,t){return new o((r,e)=>t.fork(t=>r(n(t)),e))}function j(n,t){return new o((r,e)=>{let i,u,s=!1,c=!1;const o=n=>t=>{c||(n(t),u&&s&&e(u(i)))},f=n=>{c||(c=!0,r(n))};m(n).fork(f,o(n=>{u=n})),m(t).fork(f,o(n=>{s=!0,i=n}))})}function k(n){return n.chain(i)}class z{constructor(){this.h=new Set,this.l="inactive",this.p=new Set}emit(n){return o.all(Array.from(this.h).map(t=>t(n)||o.empty()))}subscribe(n){return this.h.add(n),this.m(),()=>{this.h.delete(n),this.m()}}clear(){this.h.clear(),this.m()}onStatusChange(n){return this.p.add(n),()=>this.p.delete(n)}m(){const n=this.h.size>0?"active":"inactive";n!==this.l&&(this.l=n,Array.from(this.p).map(t=>t(n)))}}export{f as ExternalTask,g as LoopBreak,v as LoopContinue,n as RemoteData,z as Subscription,o as Task,e as constant,i as identity,s as mapToIndexedObject,c as pairsToIndexedObject,t as range,r as to,u as toIndexedObject}; |
{ | ||
"name": "@tdreyno/pretty-please", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"files": [ | ||
@@ -28,5 +28,5 @@ "dist-*/", | ||
"@types/puppeteer": "^2.0.0", | ||
"@types/react": "^16.9.19", | ||
"@typescript-eslint/eslint-plugin": "^2.19.2", | ||
"@typescript-eslint/parser": "^2.19.2", | ||
"@types/react": "^16.9.20", | ||
"@typescript-eslint/eslint-plugin": "^2.20.0", | ||
"@typescript-eslint/parser": "^2.20.0", | ||
"commitizen": "^4.0.3", | ||
@@ -43,3 +43,3 @@ "cz-conventional-changelog": "3.1.0", | ||
"puppeteer": "^2.1.1", | ||
"semantic-release": "^17.0.3", | ||
"semantic-release": "^17.0.4", | ||
"terser": "^4.6.3", | ||
@@ -46,0 +46,0 @@ "ts-jest": "^25.2.0", |
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
Sorry, the diff of this file is not supported yet
295915
4512