We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
collect : List (Result e a) -> Result (List e) (List a)
Particularly useful for validation, it collects all the errors in the list, so they can all be shown at once to the user.
Validation almost always needs this, but pretty much any library where we want to show good error messages needs to not loose information.
This tends to be in practice more useful than Result.Extra.combine, as when using Result, we actually care about the error type.
Result.Extra.combine
Result
collect : List (Result e a) -> Result (List e) (List a) collect = List.foldr (\ra soFar -> case (ra, soFar) of (Err x, Err y) -> Err (x :: y) (Ok _, Err _) -> soFar (Err x, Ok _) -> Err [ x ] (Ok x, Ok y) -> Ok (x :: r) ) (Ok [])
or some such. Not terrible to write, but not exactly a handy one-liner either.
collect is just a spitball idea, moderate bike-shedding welcome.
collect
The text was updated successfully, but these errors were encountered:
classify? I don't love it though
classify
Sorry, something went wrong.
Also, if you do this you should have it be List (Result e a) -> Result (e, List e) (List a)
List (Result e a) -> Result (e, List e) (List a)
No branches or pull requests
collect : List (Result e a) -> Result (List e) (List a)
Particularly useful for validation, it collects all the errors in the list, so they can all be shown at once to the user.
Motivating use case
Validation almost always needs this, but pretty much any library where we want to show good error messages needs to not loose information.
Rationale
This tends to be in practice more useful than
Result.Extra.combine
, as when usingResult
, we actually care about the error type.or some such. Not terrible to write, but not exactly a handy one-liner either.
Name
collect
is just a spitball idea, moderate bike-shedding welcome.The text was updated successfully, but these errors were encountered: