You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found myself writing this function a couple times. It's a map that collects all failures. If every call to f returns Ok, the result is Ok (List b), but if one or more fail, the result is Err (List x). The implementation is straightforward, but I'm not sold on a name
collectResults: (a->Resultxb) ->Lista->Result (Listx) (Listb)
collectResults f =let
folder a res =case (f a, res)of(Ok b,Ok bs)->Ok(b :: bs)-- Collect more Ok's(Ok _,Err xs)->Err xs -- Ok's are ignored once we hit an error(Err x,Ok _)->Err[x]-- One Err causes the whole thing to Err(Err x,Err xs)->Err(x :: xs)-- Collect more Err'sinList.foldr folder (Ok[])
The function is useful when checking a bunch of input, and only passing the whole thing if all is good, but collecting (multiple) errors to show if any are bad.
The text was updated successfully, but these errors were encountered:
I've found myself writing this function a couple times. It's a map that collects all failures. If every call to
f
returnsOk
, the result isOk (List b)
, but if one or more fail, the result isErr (List x)
. The implementation is straightforward, but I'm not sold on a nameThe function is useful when checking a bunch of input, and only passing the whole thing if all is good, but collecting (multiple) errors to show if any are bad.
The text was updated successfully, but these errors were encountered: