Erlang Central

List Comprehension

Revision as of 08:32, 2 September 2006 by Rvg (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

1> L = [1,2,3,10,11,12,14].
[1,2,3,10,11,12,14]

2> [X || X <- L, X > 4].
[10,11,12,14] 

The expression [X || X <- L, X > 4] can be read as "Choose all X where X is a member of L and X is larger than 4", resulting in a very easy way to handle lists.