A.Vector.fetch

You're seeing just the function fetch, go back to A.Vector module for more information.

Specs

fetch(t(val), index()) :: {:ok, val} | :error when val: value()

Finds the element at the given index (zero-based), and returns it in a ok-entry. If the index does not exist, returns :error.

Supports negative indexing from the end of the vector.

Runs in effective constant time.

Examples

iex> A.Vector.new(1..1_000) |> A.Vector.fetch(555)
{:ok, 556}
iex> A.Vector.new(1..1_000) |> A.Vector.fetch(1_000)
:error
iex> A.Vector.new(1..1_000) |> A.Vector.fetch(-1)
{:ok, 1000}