OkThen.Result.Enum.collect
You're seeing just the function
collect
, go back to OkThen.Result.Enum module for more information.
Link to this function
collect(results)
Specs
collect([OkThen.Result.tagged()]) :: {atom(), [any()]}
Collects an Enum of results into a single result. If all results were tagged :ok
, then a
result will be returned tagged with :ok
, whose value is a list of the wrapped values from each
element in the list. Otherwise, the result whose tag didn't match tag
is returned.
Equivalent to collect_tagged(results, :ok)
. See collect_tagged/2
.
Examples
iex> [:ok, :ok]
...> |> Result.Enum.collect()
{:ok, [{}, {}]}
iex> [:ok, :ok, :ok, :error, {:error, 2}]
...> |> Result.Enum.collect()
{:error, {}}
iex> [{:ok, 1}, {:ok, 1, 2}, :ok]
...> |> Result.Enum.collect()
{:ok, [1, {1, 2}, {}]}
iex> [{:ok, 1}, {:ok, 1, 2}, {:something, 1}, :ok]
...> |> Result.Enum.collect()
{:something, 1}