List Comprehensions

List comprehensions in Erlang use || as a separator between expression and generators, but | is used in Hamler.

Hamler:

  1. [x*2 | x <- [1,2,3]] -- [2,4,6]
  2. -- multiple generators
  3. [(x,y) | x <- [1,2,3], y <- [4,5]]
  4. -- dependent generators
  5. [(x,y) | x <- [1..3], y <- [x..3]]
  6. -- Conditions
  7. even i = 0 == i % 2
  8. [x | x <- [1..10], even x]

Erlang:

  1. [X*2 || X <- [1,2,3]]. %% [2,4,6]
  2. -- multiple generators
  3. [{X, Y} || X <- [1,2,3], Y <- [4,5]].
  4. -- dependent generators
  5. [{X, Y} || X <- [1,2,3], Y <- lists:seq(X,3)].
  6. -- Conditions
  7. even(I) -> 0 == (I rem 2).
  8. [X || X <- lists:seq(1, 10), even(X)].