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.
-- with the purity inference change
I think it's probably worth having long-term
just so you can use it in a pipeline, unlike for
It would be good to have map! also
I'm not sure about that one
I mean we definitely could, I'd just rather wait and see if there's actually demand for it in practice
In updating wasm4, I hit a handful of instance of needing forEach. I also hit an instance of needing forEachWithIndex
Yeah, I’m not convinced about map!, but walk! would make sense
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.
But all of those can be added later.
For now, recursion is fine
Then when we see enough uses, just add one to the standard
Last updated: Jun 16 2026 at 16:19 UTC