Stream: beginners

Topic: List.map List.map


view this post on Zulip Brendan Hansknecht (Oct 08 2022 at 23:31):

Is there a proper way to do nested List.maps? Would it be reasonable/possible to add a builtin in the form of List.innermostMap that always runs on the elements of the innermost List. Some times when processing strings I get types like List (List U8). There have been other cases ase well, but it just seems inconvenient.

view this post on Zulip Ayaz Hafiz (Oct 08 2022 at 23:33):

List.map l1 \inner -> List.map inner doInnerItem?

view this post on Zulip Ayaz Hafiz (Oct 08 2022 at 23:35):

I don't think it's too bad

view this post on Zulip Ayaz Hafiz (Oct 08 2022 at 23:36):

Do empathize how it could get annoying after a while though

view this post on Zulip Brendan Hansknecht (Oct 09 2022 at 00:10):

Yeah, That is what I am doing. Just don't like it that much.

This pipeline just is more eh in my opinion.

    |> List.map (\x ->
        x
        |> List.reverse
        |> List.map flipBracket
        |> scoreClosing
    )

view this post on Zulip Brendan Hansknecht (Oct 09 2022 at 00:10):

But yeah, it does work

view this post on Zulip Richard Feldman (Oct 09 2022 at 00:17):

https://github.com/roc-lang/roc/issues/4139 would mean it wouldn't need parens

view this post on Zulip Brendan Hansknecht (Oct 09 2022 at 01:54):

Which definitely does help a bit. Though still feels less satisfying than I would hope

view this post on Zulip Anton (Oct 10 2022 at 09:19):

I'd agree that this would come up often enough (especially in data science) to add a builtin for it. Starting the function's name with map may also make it more discoverable so: List.mapInner or list.mapInnermost.


Last updated: Jul 06 2025 at 12:14 UTC