Noether.List (noether v0.2.5)
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()
fun2()
Link to this section Functions
sequence(a)
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
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)
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
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)
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
Examples
iex> zip_with([1, 2, 3], [4, 5, 6], &Kernel.+/2)
[5, 7, 9]