A.Vector.with_index
You're seeing just the function
with_index
, go back to A.Vector module for more information.
Specs
with_index(t(val), index()) :: t({val, index()}) when val: value()
with_index(t(val), (val, index() -> mapped_val)) :: t(mapped_val) when val: value(), mapped_val: value()
Returns the vector
with each element wrapped in a tuple alongside its index.
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 vector
.
Runs in linear time.
Examples
iex> vector = A.Vector.new(["foo", "bar", "baz"])
iex> A.Vector.with_index(vector)
vec([{"foo", 0}, {"bar", 1}, {"baz", 2}])
iex> A.Vector.with_index(vector, 100)
vec([{"foo", 100}, {"bar", 101}, {"baz", 102}])
iex> A.Vector.with_index(vector, fn element, index -> {index, element} end)
vec([{0, "foo"}, {1, "bar"}, {2, "baz"}])