Slide 20
Slide 20 text
I ❤ for comprehensions
# Every combination of 2 elements in list, order independent
iex> list = [1, 2, 3, 4]
iex> for x <- list, y <- list, x < y, do: [x, y]
[[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
# What if the list items are not of the same type?
iex> list = [:a, 3.14, -5, "Z"]
iex> for x <- list, y <- list, x < y, do: [x, y]
[[:a, "Z"], [3.14, :a], [3.14, "Z"], [-5, :a], [-5, 3.14], [-5, "Z"]]
Total Term Ordering:
number < atom < reference < function < port < pid < tuple < map < list < bitstring