Skip to content

Commit b7426cc

Browse files
authored
Merge pull request #863 from lierdakil/sequence-comp
Remove old "sequence comprehensions" in tour
2 parents a470144 + aabd0ca commit b7426cc

File tree

2 files changed

+13
-71
lines changed

2 files changed

+13
-71
lines changed

_tour/for-comprehensions.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,16 @@ Here `n == 10` and `v == 10`. On the first iteration, `i == 0` and `j == 0` so `
5151
5252
(0, 0) (0, 1) (0, 2) (0, 3) (0, 4) (0, 5) (0, 6) (0, 7) (0, 8) (0, 9) (1, 1) ...
5353
```
54+
55+
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.
56+
57+
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`:
58+
59+
```tut
60+
def foo(n: Int, v: Int) =
61+
for (i <- 0 until n;
62+
j <- i until n if i + j == v)
63+
print(s"($i, $j)")
64+
65+
foo(10, 10)
66+
```

_tour/sequence-comprehensions.md

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)