Comprehensions
into: accepts any Collectable: lists, maps, MapSets, strings, IO.stream(), files.
into: accepts any Collectable: lists, maps, MapSets, strings, IO.stream(), files.
for x <- [1, 2, 3], do: x * x # [1, 4, 9]
for x <- 1..3, y <- [:a, :b], do: {x, y} # cartesian product
for x <- 1..10, rem(x, 2) == 0, x > 4, do: x # filters: [6, 8, 10]
for {:ok, v} <- [{:ok, 1}, {:error, 2}, {:ok, 3}], do: v # pattern filter: [1, 3]
for {k, v} <- %{a: 1, b: 2}, into: %{}, do: {k, v * 10} # build a map
for c <- ~c"hello", into: "", do: <<c - 32>> # "HELLO"
for x <- [1, 1, 2], uniq: true, do: x # [1, 2]
for x <- [1, 2, 3], reduce: 0 do
acc -> acc + x
end # 6
for <<r::8, g::8, b::8 <- pixels>>, do: {r, g, b} # binary generator