Noether.List (noether v0.2.2)
Link to this section Summary
Functions
Given a list, it returns {:ok, list}
if every element of the list is different from nil or {:error, _}
. Otherwise {:error, :nil_found}
is returned.
Given a predicate, a function of arity 1, and a value, the function is applied repeatedly until the predicate applied to the value returns either nil
, false
, or {:error, _}
. The list of results is returned.
Given two lists and a function of arity 2, the lists are first zipped and then each tuple is applied (curried) to the function.
Link to this section Types
fun1()
Specs
fun2()
Specs
Link to this section Functions
sequence(a)
Specs
Given a list, it returns {:ok, list}
if every element of the list is different from nil or {:error, _}
. Otherwise {:error, :nil_found}
is returned.
Examples
iex> sequence([1, 2])
{:ok, [1, 2]}
iex> sequence([1, nil, 3])
{:error, :nil_found}
iex> sequence([{:ok, 1}, {:ok, 2}])
{:ok, [1, 2]}
iex> sequence([{:ok, 1}, {:error, 2}, {:ok, 3}])
{:error, 2}
iex> sequence([{:error, 1}, {:error, 2}])
{:error, 1}
until(p, f, a)
Specs
Given a predicate, a function of arity 1, and a value, the function is applied repeatedly until the predicate applied to the value returns either nil
, false
, or {:error, _}
. The list of results is returned.
Examples
iex> until(fn a -> a < 10 end, &(&1 + 1), 0)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
zip_with(a, b, f)
Specs
Given two lists and a function of arity 2, the lists are first zipped and then each tuple is applied (curried) to the function.
Examples
iex> zip_with([1, 2, 3], [4, 5, 6], &Kernel.+/2)
[5, 7, 9]