cats icon indicating copy to clipboard operation
cats copied to clipboard

haskell's sequence

Open dustingetz opened this issue 8 years ago • 2 comments

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?

dustingetz avatar May 02 '17 12:05 dustingetz

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?

dustingetz avatar May 02 '17 13:05 dustingetz

:+1: for generic sequence and traverse for all functorial types f t where (satisfies? Seqable t).

yurrriq avatar May 02 '17 20:05 yurrriq