Skip to content

Commit a2c2213

Browse files
committed
Merge pull request elixir-lang#666 from aercolino/patch-1
Removed ambiguity about filter: "filter out" means discard.
2 parents 08a9a7f + 9cc6c15 commit a2c2213

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

getting-started/comprehensions.markdown

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ iex> for {:good, n} <- values, do: n * n
3535
[1, 4, 16]
3636
```
3737

38-
Alternatively to pattern matching, filters can be used to filter some particular elements out. For example, we can filter out all the multiples of 3 and get the square of the remaining values only:
38+
Alternatively to pattern matching, filters can be used to select some particular elements. For example, we can select the multiples of 3 and discard all others:
3939

4040
```iex
4141
iex> multiple_of_3? = fn(n) -> rem(n, 3) == 0 end
4242
iex> for n <- 0..5, multiple_of_3?.(n), do: n * n
4343
[0, 9]
4444
```
4545

46-
Comprehensions filter out all elements for which the filter expression returns `false` or `nil`; all other values are kept.
46+
Comprehensions discard all elements for which the filter expression returns `false` or `nil`; all other values are selected.
4747

4848
Comprehensions generally provide a much more concise representation than using the equivalent functions from the `Enum` and `Stream` modules. Furthermore, comprehensions also allow multiple generators and filters to be given. Here is an example that receives a list of directories and gets the size of each file in those directories:
4949

0 commit comments

Comments
 (0)