Stream: beginners

Topic: Accumulating Ok values from List Result


view this post on Zulip Monica (Jul 07 2024 at 14:45):

Hey!
I am struggling to understand how to collect or accumulate Ok values from a List of Results.
I have a List(Result String Errors) and I'd like to get a Result (List String) Error
I've played around with using List.walk but haven't been able to get very far, so any suggestions on how to do this or any examples of something like this would be really appreciated!

view this post on Zulip Sam Mohr (Jul 07 2024 at 15:37):

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

view this post on Zulip Kilian Vounckx (Jul 07 2024 at 15:37):

I think List.mapTry is what you need. If you have the list already do List.mapTry theList \x -> x. But you probably built the list some other way, so look ik you can't use List.mapTry instead of List.map if you build it

view this post on Zulip Kilian Vounckx (Jul 07 2024 at 15:38):

Sam Mohr said:

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

Same answer :sweat_smile:

view this post on Zulip Sam Mohr (Jul 07 2024 at 15:42):

Yeehaw

view this post on Zulip Monica (Jul 07 2024 at 16:25):

ahh that's exactly what I was looking for, thanks guys!! :innocent:

view this post on Zulip Brian Carroll (Jul 07 2024 at 17:47):

You might also check out keepOks
https://www.roc-lang.org/builtins/List#keepOks


Last updated: Jul 06 2025 at 12:14 UTC