Stream: beginners

Topic: how to do map for 2d structures


view this post on Zulip Artur Swiderski (May 22 2023 at 20:59):

this is no directly roc related, but how one does map when there is 2d structure to be modified, one has to combine list of lists somehow or there is some native support for that?

view this post on Zulip Ajai Nelson (May 22 2023 at 21:30):

I'm not totally sure if I'm understanding your question right, but if you want to map over every element in a list of lists, you could use nested List.maps:

listOfLists = [[1, 2, 3], [4, 5, 6]]

List.map listOfLists \list ->
    List.map list \num ->
        num + 1
# => [[2, 3, 4], [5, 6, 7]]

view this post on Zulip drew (May 22 2023 at 21:56):

If you want to "flatten out" the structure while mapping, you could use List.joinMap plus backpassing https://gist.github.com/drewolson/3c5a44e4ea177995a675541fbc50aee2


Last updated: Jul 06 2025 at 12:14 UTC