diff --git a/_overviews/scala3-book/scala-for-python-devs.md b/_overviews/scala3-book/scala-for-python-devs.md index 147f5977f..551bd1426 100644 --- a/_overviews/scala3-book/scala-for-python-devs.md +++ b/_overviews/scala3-book/scala-for-python-devs.md @@ -40,7 +40,7 @@ At a high level, Scala shares these *similarities* with Python: - Both have a relatively simple, concise syntax - Both support a [functional style of programming][fp-intro] - Both are object-oriented programming (OOP) languages -- Both have comprehensions: Python has list comprehensions and Scala has `for` comprehensions +- Both have comprehensions: Python has list comprehensions, dict comprehensions and generator expressions and Scala has `for` comprehensions - Both languages have support for lambdas and [higher-order functions][hofs] - Both can be used with [Apache Spark](https://spark.apache.org) for big data processing - Both have a wealth of terrific libraries @@ -693,6 +693,26 @@ Scala also has `match` expressions. </tbody> </table> +### Lazily evaluated comprehensions: + +<table> + <tbody> + <tr> + <td class="python-block"> + <code>from itertools import count + <br>all_squares = (n**2 for n in count()) # generator expression + <br># all_squares: <generator object <genexpr> at ...></code> + </td> + </tr> + <tr> + <td class="scala-block"> + <code>val allSquares = for n <- LazyList.from(0) yield n * n + <br>// allSquares: LazyList(<not computed>)</code> + </td> + </tr> + </tbody> +</table> + ### `match` expressions: <table>