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

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

Open
smheidrich opened this issue Mar 24, 2025 · 0 comments

Comments

@smheidrich
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant