Skip to content

Scala for Python Developers should show equivalent of generator expressions #3178

Open
@smheidrich

Description

@smheidrich

The Scala for Python Developers page does have a section comparing Scala's comprehensions to Python's list comprehensions, but (AFAICT) lacks any information about what Scala's analogue is to Python's generator expressions, which are like list comprehensions but lazily evaluated.

From the answers to a StackOverflow question about this, I got that in Scala, lazy evaluation or not is decided by the object being iterated over, because comprehensions just desugar to object.map() calls and the like, which of course get to determine the output type in full (unlike Python, where iterated-over objects only get to determine the element type).

It would be nice if one equivalent to a generator expression using a .view or something like that was briefly demonstrated, maybe with a short comment explaining this (although it seems like the existing examples are kept comment-free on purpose, so maybe not if the goal is to really keep it short - but in that case, maybe there could be a longer explanation further down the page).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions