Comprehensions in Elixir have the following syntax:
Generators such as
x are named local variables you can use in the
Note that variable assignments such as
x in comprehensions are local in scope, so it doesn’t affect variables with the same name in the outer scope.
We can have multiple generators
We can use filters alongside generators. When the condition in the filter evaluates to false, that particular iteration is skipped.
Unlike guard clauses, you can call your own module’s methods within filter.
into parameter takes in a collection for storing the comprehension’s results:
We can also use pattern matching in comprehensions: