Stream: ideas

Topic: convert List of Results into Result of List


view this post on Zulip Richard Feldman (Jul 07 2024 at 17:56):

Sam Mohr said:

Monica try throwing the identity function at https://www.roc-lang.org/builtins/List#mapTry

whenever "pass the identity function" is the best answer, I always suspect there's a missing function in the API, and this seems like one of those situations :big_smile:

view this post on Zulip Richard Feldman (Jul 07 2024 at 17:57):

what would be a good name for a function like this to add to List?

List (Result ok err) -> Result (List ok) err

view this post on Zulip Richard Feldman (Jul 07 2024 at 17:57):

maybe List.tryAll or something like that?

view this post on Zulip Richard Feldman (Jul 07 2024 at 17:57):

perhaps List.try

view this post on Zulip Kevin Gillette (Jul 07 2024 at 22:56):

Did these _already_ get "tried" by virtue of already being results (rather than tasks)? I don't recall if there's a naming precedent established for this kind of thing in Roc yet.

view this post on Zulip Kevin Gillette (Jul 07 2024 at 22:59):

And does it make more sense to have lists know about results rather than results knowing about lists?

A list seems more fundamental to me, thus the result module knowing about any number of things seems more natural than the list module knowing directly about list elements representing failure.

view this post on Zulip Francois Green (Jul 08 2024 at 17:40):

Maybe adding the function to Result, like sequence with Task would be easier to learn.

sequence : List (Result ok err) -> Result (List ok) err

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 17:42):

I think for result specifically mirroring Result.try with Result.tryAll makes most sense.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 17:43):

sequence/sequential makes sense on Task cause they are actually run in order.

view this post on Zulip Brendan Hansknecht (Jul 08 2024 at 17:43):

Results are already generated outputs. On top of that, this would only be for List not for generic sequences.

view this post on Zulip Sam Mohr (Jul 08 2024 at 18:39):

Result.tryAll is a good option! I like that it is concise, but still tells the reader "we're working with a list of results". I think List.tryis less obvious on that front.


Last updated: Jun 16 2026 at 16:19 UTC