Erlang provides Lists Comprehensions to build or modify lists. List Comprehensions in Erlang are about building sets from other sets.

LC is based off the idea of set notation, set notation basically tells you how to build a set by specifying properties its members must satisfy.

In the post Handling lists with erlang – part 1 : start using lists I have shown how to build a list of the even integers number less than 100 using the seq function.

With LC we are going to define the set in the following way:

We want all the X contained in N (Integer numbers) such that X < 100 and the remainder of the division by 2 is 0.
So we can write the code:```
1> EvenNumbers = [X || X <- lists:seq(0, 100), X rem 2 == 0].
[0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,
42,44,46,48,50,52,54,56|...]
2>
```

This is a preview of

Handling lists with erlang – part 2 : Lists Comprehensions

.

Read the full post (162 words, 1 image, estimated 39 secs reading time)
## Latest Comments