Here is an example of group_by/3 in Enum module.
Grouping an array of strings based on its length:
iex(12)> ["ant", "buffalo", "cat", "dingo"] |> Enum.group_by(&String.length/1)
%{3 => ["cat", "ant"], 5 => ["dingo"], 7 => ["buffalo"]}
From the docs:
Splits collection into groups based on a fun.
The result is a dict (by default a map) where each key is a group and each value is a list of elements from collection for which fun returned that group. Ordering is not necessarily preserved.