Closed mohsensaremi closed 4 years ago
Fluture is inherently a "railway oriented programming" library.
You don't need your own implementation of bind
, because chain
is monadic bind
.
Note also that your bind
is just Future.encase
, and your bindAsync
is actually just Future.encaseP
. So you could have written:
const bind = Future.encase
const bindAsync = Future.encaseP
Furthermore, chain (encase (f))
is equivalent to map (f)
(assuming f
doesn't throw). So in that case, your code can be changed altogether into the following:
Future.of("TEST")
.map(doThis)
.map(doThat)
.chain(encaseP(doThisAsync))
.chain(encaseP(doThatAsync))
.map(doAnotherThing)
.chain(encaseP(doAnotherThingAsync))
By the way, you are welcome to join our Gitter chat room for small questions like this - usually you can get a faster answer there. There's also a stack overflow tag under which you can ask Fluture-related questions.
Closing this as I don't see further action to be taken.
Railway Oriented Programming(ROP) is explained here: https://fsharpforfunandprofit.com/rop/
Is there any way to use this pattern with
Fluture
I can do ROP with these two helper methods like this:
Is there a better way to remove
bind
,bindAsync
and do binding automatically?