5 Enum Module

5.1 Looping

Enum.each(
    [1, 2, 3],
    fn (x) -> IO.puts(x) end
)
#> 1
#> 2
#> 3
#> :ok

Use the capture operator & as a shortcut, it takes the full function qualifier — a module name, a function name, and an arity — and turns that function into a lambda that can be assigned to a variable. You can use the capture operator to simplify the call to Enum.each:

Enum.each(
    [1, 2, 3],
    &IO.puts/1
)

5.2 Counting

Enum.count

iex(6)> Enum.count([1, 2, 3])
#> 3
iex(7)> Enum.count({a: 1, b: 2})
#> 2

5.3 Using Stream