Enum.fetch
You're seeing just the function
fetch
, go back to Enum module for more information.
Specs
Finds the element at the given index
(zero-based).
Returns {:ok, element}
if found, otherwise :error
.
A negative index
can be passed, which means the enumerable
is
enumerated once and the index
is counted from the end (for example,
-1
fetches the last element).
Examples
iex> Enum.fetch([2, 4, 6], 0)
{:ok, 2}
iex> Enum.fetch([2, 4, 6], -3)
{:ok, 2}
iex> Enum.fetch([2, 4, 6], 2)
{:ok, 6}
iex> Enum.fetch([2, 4, 6], 4)
:error