From 01450a1fd9d6311bcde335f897fd5c99b45c067f Mon Sep 17 00:00:00 2001 From: ali hong Date: Mon, 4 Mar 2024 03:23:05 -0600 Subject: [PATCH] Link out to wiki page for the concept of a "generator" (#2985) * 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 Co-authored-by: Jamie Thompson --- _overviews/scala3-book/control-structures.md | 2 +- _overviews/scala3-book/taste-control-structures.md | 3 ++- _tour/for-comprehensions.md | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/_overviews/scala3-book/control-structures.md b/_overviews/scala3-book/control-structures.md index fe94b30dc..6598cb604 100644 --- a/_overviews/scala3-book/control-structures.md +++ b/_overviews/scala3-book/control-structures.md @@ -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: diff --git a/_overviews/scala3-book/taste-control-structures.md b/_overviews/scala3-book/taste-control-structures.md index 3427c2939..4b58abbf0 100644 --- a/_overviews/scala3-book/taste-control-structures.md +++ b/_overviews/scala3-book/taste-control-structures.md @@ -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 %} diff --git a/_tour/for-comprehensions.md b/_tour/for-comprehensions.md index a21138023..a97758d8b 100644 --- a/_tour/for-comprehensions.md +++ b/_tour/for-comprehensions.md @@ -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: