what if instead of having separate functions for walk/walkWithIndex, walkBackwards/walkBackwardsWithIndex we had the "with index" ones be the norm? Like you always get the index as an argument and you can ignore it with _ if you don't care
I've noticed I reach for the "with index" versions more often than not when walking, and the index is already computed behind the scenes anyway, so passing it shouldn't have any extra runtime cost (after specialization) if it's unused, because it'll get dead argument eliminated by llvm
(in contrast, I find it's the reverse with map - I rarely use the "with index" version, and I often pass a function to map by name, so I don't think it makes sense to be the default for map)
That sounds like a good idea. I definitely have a number of cases where I have manually added the index to the state. I think it is pretty common.
Agreed. Without partial application I see only upsides to this.
I went through updating a ton of usages of List.walk in the roc-lang/roc repo, and it seemed like the index was used maybe 5-10% of the time
I also noticed that the index is only ever used in any of these examples when going forward and not using Until, so I think having just List.walkWithIndex feels like the right balance for now
I'm gonna make a PR to add that and see how it feels
https://github.com/roc-lang/roc/pull/5764
Last updated: Jun 16 2026 at 16:19 UTC