scala / docs.scala-lang

The Scala Documentation website
http://docs.scala-lang.org
559 stars 1.02k forks source link

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

Closed hongtron closed 6 months ago

hongtron commented 6 months ago

The term "generator" is used in a couple spots in the docs (e.g. in For Comprehensions in the Tour of Scala), but is never defined. As an alternative to this change, I welcome (and would even prefer) proposed definitions for the term, if the Scala concept does not completely line up with the wiki content - but I do not feel qualified to venture a definition myself.

bishabosha commented 6 months ago

Hey, thank you for opening this PR! We can definitely do more to make a reusable definition to explain what is meant by "generator". Probably the best is from this page

The code i <- ints is referred to as a generator.

Perhaps we can copy that to the tour and a taste of scala

My suggestion for improvement would be

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.

hongtron commented 6 months ago

Thank you for your feedback! I've pushed some changes to incorporate your definition, and update the other spots you called out.

I also made two other wording changes, which I've broken into separate commits for emphasis (one regarding the phrase "semicolon-separated," and one replacing "filter" with "guard"). Let me know if you think they make sense.