Types.Recipients: Simplify reducer.
This commit is contained in:
parent
a35b76431c
commit
9249742f13
1 changed files with 7 additions and 5 deletions
|
@ -11,11 +11,13 @@ def cast(object) when is_binary(object) do
|
||||||
|
|
||||||
def cast(data) when is_list(data) do
|
def cast(data) when is_list(data) do
|
||||||
data
|
data
|
||||||
|> Enum.reduce({:ok, []}, fn element, acc ->
|
|> Enum.reduce_while({:ok, []}, fn element, {:ok, list} ->
|
||||||
case {acc, ObjectID.cast(element)} do
|
case ObjectID.cast(element) do
|
||||||
{:error, _} -> :error
|
{:ok, id} ->
|
||||||
{_, :error} -> :error
|
{:cont, {:ok, [id | list]}}
|
||||||
{{:ok, list}, {:ok, id}} -> {:ok, [id | list]}
|
|
||||||
|
_ ->
|
||||||
|
{:halt, :error}
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue