You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with promises I've found it useful to consume functions regardless of them returning a plain value or a promise. Thus I can always chain these arbitrary functions in "promise-style" f1().then(f2). ... i.e. with Ramda R.composeP(f1, f2).
I think it would be useful to have this for Tasks as well:
varR=require('ramda');// just for my convenience writing this implementation - sorry!vartoPromise=Promise.resolve.bind(Promise);// helper// takes a function func which returns a value, Promise or Task and returns a function which// will return a Task.vartaskify=function(func){returnR.compose(R.unless(R.is(Task),R.compose(Task.fromPromise,toPromise)),func);};// examples:taskify((x,y)=>x+y)(8,9).runAndLog();// -> Success: 17taskify((x,y)=>Promise.resolve(x+y))(8,9).runAndLog();// -> Success: 17taskify((x,y)=>Task.of(x+y))(8,9).runAndLog();// -> Success: 17
What do you think?
The text was updated successfully, but these errors were encountered:
When working with promises I've found it useful to consume functions regardless of them returning a plain value or a promise. Thus I can always chain these arbitrary functions in "promise-style"
f1().then(f2). ...
i.e. with RamdaR.composeP(f1, f2)
.I think it would be useful to have this for Tasks as well:
What do you think?
The text was updated successfully, but these errors were encountered: