Does elixir Enum or any other module have a group_by function similar to ruby ​​group_by

Ruby has this wonderful group_by method for Enumerable. Does Elixir have something similar? I could not find this function in the Enum module. thank

+3
source share
2 answers

Here is an example of group_by / 3 in the 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:

Dividing a collection into groups based on pleasure.

The result is a dict (default map), where each key is a group, and each value is a list of items from the collection for which fun returned this group. The order is not necessarily saved.

+3
source

. , . v0.13.:)

* *
, , .

+4

All Articles