List comprehensions are a syntactic construct to create a list based on existing lists.
In erlang a list comprehension has the form [Expr || Qualifier1, ..., QualifierN]
.
Where qualifiers are either generators Pattern <- ListExpr
or filter like integer(X)
evaluating to either true
or false
.
The following example shows a list comprehension with one generator and two filters.
[X || X <- [1,2,a,3,4,b,5,6], integer(X), X > 3].
The result is a list containing only integers greater than 3.
[4,5,6]