-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Description
I was recently using the Enum.with_index/1 function but did not want to start with an index of 0, then realized that this is not supported.
This is the proposal:
collection = ~w( a b c )
Enum.with_index(collection, 3)
# => [{"a", 3}, {"b", 4}, {"c", 5}]These are alternative ways to accomplish this:
collection = ~w( a b c )
offset = 3
# Very similar to the current implementation of .with_index/1
collection
|> Enum.map_reduce(offset, fn (current, i) -> {{current, i}, i + 1} end
|> elem(0)
# => [{"a", 3}, {"b", 4}, {"c", 5}]
# Leverage Enum.with_index/1 and Enum.map/2
collection
|> Enum.with_index
|> Enum.map(fn {el, i} -> {el, i + offset} end)
# => [{"a", 3}, {"b", 4}, {"c", 5}]
I believe the proposal would be a more elegant way of accomplishing this.
I'd be happy to implement this. This seems simple enough for a first time contributor to accomplish easily. What do you guys think?
Metadata
Metadata
Assignees
Labels
No labels