Recently I had a
let in which it would be convenient if the whole expression would short-circuit if one of the bindings would be
This is what the
Maybe monad can be used for and funcool cats offers this in the form of
mlet, so I could have used that (but I didn’t).
(def sum1 (m/mlet [a (maybe/just 1) b (maybe/just 2)] (m/return (+ a b)))) ;;=> #<Just 3> (def sum2 (m/mlet [a (maybe/just 1) b nil] (m/return (+ a b)))) ;;=> nil (def sum3 (m/mlet [a (maybe/just 1) b (maybe/nothing)] (m/return (+ a b)))) ;;=> #<Nothing> (map maybe/from-maybe [sum1 sum2 sum3]) ;;=> (3 nil nil)
So even in small contexts this library can be useful without imposing category theory on colleagues in the rest of the codebase…
Of course you can also use
some-> for this, but this doesn’t let you name bindings.
I wonder if anyone has used funcool cats in real world projects and got any leverage out of it?