Stream: ideas

Topic: Temporary `List.forEach` impl until `for`


view this post on Zulip Luke Boswell (Oct 23 2024 at 01:51):

What do people (@Richard Feldman) think about including this as a builtin until we have for and var implemented?

# List.roc
forEach! : List a, (a => {}) => {}
forEach! = \l, f! ->
    when l is
        [] -> {}
        [x, .. as xs] ->
            f! x
            forEach! xs f!

It's really helpful, but non-obvious how to implement.

view this post on Zulip Luke Boswell (Oct 23 2024 at 01:52):

-- with the purity inference change

view this post on Zulip Richard Feldman (Oct 23 2024 at 01:53):

I think it's probably worth having long-term

view this post on Zulip Richard Feldman (Oct 23 2024 at 01:53):

just so you can use it in a pipeline, unlike for

view this post on Zulip Isaac Van Doren (Oct 23 2024 at 02:02):

It would be good to have map! also

view this post on Zulip Richard Feldman (Oct 23 2024 at 02:02):

I'm not sure about that one

view this post on Zulip Richard Feldman (Oct 23 2024 at 02:03):

I mean we definitely could, I'd just rather wait and see if there's actually demand for it in practice

view this post on Zulip Brendan Hansknecht (Oct 23 2024 at 02:24):

In updating wasm4, I hit a handful of instance of needing forEach. I also hit an instance of needing forEachWithIndex

view this post on Zulip Agus Zubiaga (Oct 23 2024 at 02:27):

Yeah, I’m not convinced about map!, but walk! would make sense

view this post on Zulip Brendan Hansknecht (Oct 23 2024 at 02:31):

I mean map! for loading a bunch of files or similar makes sense. Though if possible, I would guess that some sort of mapParallel! would actually be what is wanted.

view this post on Zulip Brendan Hansknecht (Oct 23 2024 at 02:32):

But all of those can be added later.

view this post on Zulip Brendan Hansknecht (Oct 23 2024 at 02:32):

For now, recursion is fine

view this post on Zulip Brendan Hansknecht (Oct 23 2024 at 02:32):

Then when we see enough uses, just add one to the standard


Last updated: Jun 16 2026 at 16:19 UTC