Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions _tour/for-comprehensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,16 @@ Here `n == 10` and `v == 10`. On the first iteration, `i == 0` and `j == 0` so `

(0, 0) (0, 1) (0, 2) (0, 3) (0, 4) (0, 5) (0, 6) (0, 7) (0, 8) (0, 9) (1, 1) ...
```

Note that comprehensions are not restricted to lists. Every datatype that supports the operations `withFilter`, `map`, and `flatMap` (with the proper types) can be used in sequence comprehensions.

You can omit `yield` in a comprehension. In that case, comprehension will return `Unit`. This can be useful in case you need to perform side-effects. Here's a program equivalent to the previous one, but without using `yield`:

```tut
def foo(n: Int, v: Int) =
for (i <- 0 until n;
j <- i until n if i + j == v)
print(s"($i, $j)")

foo(10, 10)
```
71 changes: 0 additions & 71 deletions _tour/sequence-comprehensions.md

This file was deleted.