A.Enum.with_index
You're seeing just the function
with_index
, go back to A.Enum module for more information.
Specs
with_index(t(val), index()) :: [{val, index()}] when val: value()
with_index(t(val), (val, index() -> mapped_val)) :: [mapped_val] when val: value(), mapped_val: value()
Returns a list with with each element of enumerable
wrapped in a tuple alongside its index.
Mirrors Enum.with_index/2
(Elixir 1.12 version): may receive a function or an integer offset.
If an integer offset
is given, it will index from the given offset
instead of from zero.
If a function
is given, it will index by invoking the function for each
element and index (zero-based) of the enumerable
.
Examples
iex> A.Enum.with_index([:a, :b, :c])
[a: 0, b: 1, c: 2]
iex> A.Enum.with_index([:a, :b, :c], 3)
[a: 3, b: 4, c: 5]
iex> A.Enum.with_index([:a, :b, :c], fn element, index -> {index, element} end)
[{0, :a}, {1, :b}, {2, :c}]