cats
cats copied to clipboard
haskell's sequence
What's the idiomatic way to turn list-of-maybe into maybe-list? I believe promesa calls this p/all (but defers to native implementation), how do I do this on Maybe or Exception?
Here is an answer with concrete types for the next guy:
(->> [(exception/success 1) #_(exception/failure 42) (exception/success 2)]
(reduce #(mlet [acc %1 v %2] (cats/return (conj acc v))) (exception/success [])))
=> #<Success [1 2]>
(->> [(exception/success 1) (exception/failure 42) (exception/success 2)]
(reduce #(mlet [acc %1 v %2] (cats/return (conj acc v))) (exception/success [])))
=> #<Failure #error {:message "", :data 42}>
Shouldn't this be provided by the library?
:+1: for generic sequence and traverse for all functorial types f t where (satisfies? Seqable t).