7 ms·
(res, err) is Either monad, isn't it?
by dottedmag 4y ago
(res, err) is Either monad, isn't it?
- spion 4y agoIts not a single value, so its not anything.
- spion 4y agoThat may've sounded overly harsh - but as a first step, try for example to use the output of a Go function that returns two values in another expression. e.g. assuming `g` returns (err, res), try writing `f` in such a way that you can call `f(g(x))`. This has implications on how higher order functions like `map`, `filter` etc can be written in a way that makes them usable with any value (including those that represent an error)
- dottedmag 4y agofunc composeE[T](fn1, fn2 func(T, error) (T, error)) func(T, error) (T, error) func liftE[T](func(t T) T) func(T, error) (T, error) ? I'm not a big fan of functional programming though.
- spion 4y agoI think you might want the opposite of liftE, i.e. to be able to convert any function with two returning values into a function with a single returning value. Then you can use those functions normally with standard FP tools such as `map` etc. Yes, the node.js community did something like that with (err, res) and it still does it. Its pretty awful to be unable to use any of the standard library or community library functions (that can error) in a... functional way without wrapping them.