Enum.flat_map
You're seeing just the function
flat_map
, go back to Enum module for more information.
Specs
Maps the given fun
over enumerable
and flattens the result.
This function returns a new enumerable built by appending the result of invoking fun
on each element of enumerable
together; conceptually, this is similar to a
combination of map/2
and concat/1
.
Examples
iex> Enum.flat_map([:a, :b, :c], fn x -> [x, x] end)
[:a, :a, :b, :b, :c, :c]
iex> Enum.flat_map([{1, 3}, {4, 6}], fn {x, y} -> x..y end)
[1, 2, 3, 4, 5, 6]
iex> Enum.flat_map([:a, :b, :c], fn x -> [[x]] end)
[[:a], [:b], [:c]]