Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link out to wiki page for the concept of a "generator" #2985

Merged
merged 5 commits into from
Mar 4, 2024
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
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