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!
@Monica try throwing the identity function at https://www.roc-lang.org/builtins/List#mapTry
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
Sam Mohr said:
Monica try throwing the identity function at https://www.roc-lang.org/builtins/List#mapTry
Same answer :sweat_smile:
Yeehaw
ahh that's exactly what I was looking for, thanks guys!! :innocent:
You might also check out keepOks
https://www.roc-lang.org/builtins/List#keepOks
Last updated: Jul 06 2025 at 12:14 UTC