solution v1.0.2 Solution.Enum View Source
Helper functions to work with ok/error tuples in Enumerables.
Link to this section Summary
Functions
Changes a list of oks into {:ok, list_of_values}
Returns a list of the values of all error
-type elements in the enumerable.
Returns a list of the tuple-values of all error
-type elements in the enumerable.
Returns a list of only all error
-type elements in the enumerable.
Returns a list of the values of all ok
-type elements in the enumerable.
Returns a list of the tuple-values of all ok
-type elements in the enumerable.
Returns a list of only all ok
-type elements in the enumerable.
Link to this section Functions
combine(enum) View Source
Changes a list of oks into {:ok, list_of_values}
If any element of the list is an error, returns this error element.
If all elements are oks, takes the first non-tag value from each of them for the list.
(in the case of :ok
, nothing is added to the resulting list.)
iex> combine([{:ok, 1}, {:ok, "a", %{meta: "this will be dropped"}}, {:ok, :asdf}])
{:ok, [1, "a", :asdf]}
iex> combine([{:ok, 1}, {:ok, 2}, {:error, 3}])
{:error, 3}
iex> combine([{:ok, 1}, {:ok, 2}, {:error, 3, 4, 5}])
{:error, 3, 4, 5}
error_vals(enum) View Source
Returns a list of the values of all error
-type elements in the enumerable.
Note that the 'value' is taken to be the first element:
iex> error_vals([{:error, 1}, {:error, 2,3,4,5}])
[1, 2]
error_valstuples(enum) View Source
Returns a list of the tuple-values of all error
-type elements in the enumerable.
The 'tuple-value' consists of all elements in the error
-type element,
except for the initial :error
tag.
iex> error_valstuples([{:error, 1}, {:error, 2,3,4,5}])
[{1}, {2,3,4,5}]
errors(enum) View Source
Returns a list of only all error
-type elements in the enumerable.
iex> errors([{:ok, 1}, {:error, 2}, {:ok, 3}])
[{:error, 2}]
ok_vals(enum) View Source
Returns a list of the values of all ok
-type elements in the enumerable.
Note that the 'value' is taken to be the first element:
iex> ok_vals([{:ok, 1}, {:ok, 2,3,4,5}])
[1, 2]
ok_valstuples(enum) View Source
Returns a list of the tuple-values of all ok
-type elements in the enumerable.
The 'tuple-value' consists of all elements in the ok
-type element,
except for the initial :ok
tag.
iex> ok_valstuples([{:ok, 1}, {:ok, 2,3,4,5}])
[{1}, {2,3,4,5}]
oks(enum) View Source
Returns a list of only all ok
-type elements in the enumerable.
iex> oks([{:ok, 1}, {:error, 2}, {:ok, 3}])
[{:ok, 1}, {:ok, 3}]