You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _tour/for-comprehensions.md
+5-12Lines changed: 5 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,6 @@ val twentySomethings =
34
34
twentySomethings.foreach(println) // prints Travis Dennis
35
35
```
36
36
{% endtab %}
37
-
38
37
{% tab 'Scala 3' for=for-comprehensions-01 %}
39
38
```scala
40
39
caseclassUser(name: String, age: Int)
@@ -54,7 +53,6 @@ twentySomethings.foreach(println) // prints Travis Dennis
54
53
{% endtab %}
55
54
{% endtabs %}
56
55
57
-
58
56
A `for` loop with a `yield` statement returns a result, the container type of which is determined by the first generator. `user <- userBase` is a `List`, and because we said `yield user.name` where `user.name` is a `String`, the overall result is a `List[String]`. And `if user.age >=20 && user.age < 30` is a guard that filters out users who are not in their twenties.
59
57
60
58
Here is a more complicated example using two generators. It computes all pairs of numbers between `0` and `n-1` whose sum is equal to a given value `v`:
0 commit comments