View Source Fey.EnumR (Fey v0.0.3)
Functions similar to those in Fey.Enum
, but returning result tuples ({:ok, value}
or {:error, :not_found}
)
instead of option types.
Summary
Functions
Returns the element at the specified index
in the enum
.
Returns the first element in enum
for which fun
returns a truthy value.
Functions
@spec at(Enumerable.t(), integer()) :: Fey.Result.t(any())
Returns the element at the specified index
in the enum
.
If the index is out of bounds, returns {:error, :not_found}
.
Examples
iex> Fey.EnumR.at([1, 2, 3], 0)
{:ok, 1}
iex> Fey.EnumR.at([1, 2, 3], 5)
{:error, :not_found}
@spec find(Enumerable.t(), (any() -> as_boolean(term()))) :: Fey.Result.t(any())
Returns the first element in enum
for which fun
returns a truthy value.
If no such element is found, returns {:error, :not_found}
.
Examples
iex> Fey.EnumR.find([1, 2, 3], fn x -> x > 2 end)
{:ok, 3}
iex> Fey.EnumR.find([1, 2, 3], fn x -> x > 5 end)
{:error, :not_found}