Types.Recipients: Simplify reducer.
authorlain <lain@soykaf.club>
Sun, 3 May 2020 13:28:24 +0000 (15:28 +0200)
committerlain <lain@soykaf.club>
Sun, 3 May 2020 13:28:24 +0000 (15:28 +0200)
lib/pleroma/web/activity_pub/object_validators/types/recipients.ex

index 48fe61e1a9793e289fb98343c32f48c042e503fb..408e0f6ee6e114521a85aabf0f8dabed9cdbafcb 100644 (file)
@@ -11,11 +11,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.Types.Recipients 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