Enum.group_by will get you close to what you want:
iex(4)> [{:updated, "foo"}, {:updated, "bar"}, {:created, "baz"}, {:updated, "wat"}] |> Enum.group_by(fn {x, _} -> x end)
%{
created: [created: "baz"],
updated: [updated: "foo", updated: "bar", updated: "wat"]
}
This would still require some postprocessing of the individual lists to remove the {:created, _} wrappers around the internal elements.
Alternatively, you could use Enum.reduce with an initial state of %{new: [], updated: []} and compute what you want directly.






















