Skip to content

Commit

Permalink
Link out to wiki page for the concept of a "generator" (#2985)
Browse files Browse the repository at this point in the history
* Remove version-specific syntax description about expressing a list of enumerators

* Replace 'filter' with 'guard' for consistency

* Link to the book for clarification of generator and guard control structures

* Clarify what a 'generator' is in a couple of spots

* Update _tour/for-comprehensions.md

---------

Co-authored-by: Ali Hong <[email protected]>
Co-authored-by: Jamie Thompson <[email protected]>
  • Loading branch information
3 people authored Mar 4, 2024
1 parent 5bb982d commit 01450a1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion _overviews/scala3-book/control-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ for i <- ints do println(i)
{% endtabs %}


The code `i <- ints` is referred to as a _generator_.
The code `i <- ints` is referred to as a _generator_. In any generator `p <- e`, the expression `e` can generate zero or many bindings to the pattern `p`.

This is what the result looks like in the Scala REPL:

Expand Down
3 changes: 2 additions & 1 deletion _overviews/scala3-book/taste-control-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ val ints = List(1, 2, 3, 4, 5)
for (i <- ints) println(i)
```

> The code `i <- ints` is referred to as a _generator_, and the code that follows the closing parentheses of the generator is the _body_ of the loop.
> The code `i <- ints` is referred to as a _generator_. In any generator `p <- e`, the expression `e` can generate zero or many bindings to the pattern `p`.
> The code that follows the closing parentheses of the generator is the _body_ of the loop.
{% endtab %}

Expand Down
2 changes: 1 addition & 1 deletion _tour/for-comprehensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ redirect_from:
- "/tutorials/tour/sequence-comprehensions.html"
---

Scala offers a lightweight notation for expressing _sequence comprehensions_. Comprehensions have the form `for (enumerators) yield e`, where `enumerators` refers to a semicolon-separated list of enumerators. An _enumerator_ is either a generator which introduces new variables, or it is a filter. A comprehension evaluates the body `e` for each binding generated by the enumerators and returns a sequence of these values.
Scala offers a lightweight notation for expressing _sequence comprehensions_. Comprehensions have the form `for (enumerators) yield e`, where `enumerators` refers to a list of enumerators. An _enumerator_ is either a generator, or it is a guard (see: [Control Structures](/scala3/book/control-structures.html#for-loops)). A comprehension evaluates the body `e` for each binding generated by the enumerators and returns a sequence of these values.

Here's an example:

Expand Down

0 comments on commit 01450a1

Please sign in to comment.