Types.Recipients: Simplify reducer.

This commit is contained in:
lain 2020-05-03 15:28:24 +02:00
parent a35b76431c
commit 9249742f13
1 changed files with 7 additions and 5 deletions

View File

@ -11,11 +11,13 @@ def cast(object) when is_binary(object) do
def cast(data) when is_list(data) do
data
|> Enum.reduce({:ok, []}, fn element, acc ->
case {acc, ObjectID.cast(element)} do
{:error, _} -> :error
{_, :error} -> :error
{{:ok, list}, {:ok, id}} -> {:ok, [id | list]}
|> Enum.reduce_while({:ok, []}, fn element, {:ok, list} ->
case ObjectID.cast(element) do
{:ok, id} ->
{:cont, {:ok, [id | list]}}
_ ->
{:halt, :error}
end
end)
end