Stream: contributing

Topic: Walking with an index


view this post on Zulip Chris Duncan (Oct 09 2022 at 14:23):

I just came through an Advent of Code problem that would benefit from a List.walkBackwardsWithIndex. Would y'all consider this function, alongside walkWithIndex and walkUntilWithIndex, to be useful for the Standard Library?

view this post on Zulip Brendan Hansknecht (Oct 09 2022 at 15:04):

I have no strong preference either way, but i do want to note it is very easy to create those functions. Just make your state a record with one of the values being the index.

List.walk list {index: 0, state: ...) \{index, state}, elem -> ...

Just need to increment/decrement index on each iteration.

view this post on Zulip Richard Feldman (Oct 09 2022 at 15:20):

yeah I think that one's easy enough to do with walk itself that it's not worth a separate function :big_smile:

view this post on Zulip Chris Duncan (Oct 09 2022 at 15:25):

@Brendan Hansknecht That's precisely the way that I implemented my function.


Last updated: Jul 06 2025 at 12:14 UTC