List Comprehensions


Another way to work with lists is called “List Comprehensions”, this is quite immediate, we have a list

List = [1,2,3].

and we want to iterate over every item in the list … we can do:

[Item * 2 || Item <- List].

This way we are asking a list as result of execution (using []). We are asking that every Item in List (the code after ||) must be used in the code before || (Item * 2).

So we asked a thing like:

lists:map(fun(Item) -> 2*Item end, List).

without having to define a fun! useful 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: