Closed darky closed 7 months ago
Hi @darky I have started to implement the do
functions for Option, Either and IO. More to come. You can check on the https://github.com/IBM/fp-go/tree/cleue-bind branch.
The implementation is not identical to the fp-ts
one since it should be type safe, but go does not have a way to create ad-hoc types with keys that are passed in dynamically.
So the approach I took is similar to the pattern used in optics. Instead of passing in the name of a field as a first parameter and assume that the bound state is a record, we assume that the state is of an arbitrary type S1
and binding the new value results in a type S2
. So the first parameter to the do
functions is a function of the form
func(T) func(S1) S2
where
this follows the design for the setters in optics that have the signature
func(T) func(S) S
i.e. a special case of the above.
Let me know what you think or if you have other suggestions.
Great, thanks! It's best possible solution for Go at this moment IMO! 👍
I merged the bind branch, I believe I covered all monads. Pls. let me know if anything is missing.
Hello! Thanks for fp-go! It's real FP revolution in Go 😄
fp-ts contains
bind
for any Monad Example, https://gcanti.github.io/fp-ts/modules/Either.ts.html#bindIt's allows to pass value through pipe, which very useful
Maybe it's possible to implement it somehow in fp-go?