Scala's for-comprehensions: vital feature or syntactic sugar?

后端 未结 5 1791
南笙
南笙 2021-01-31 20:04

When I first started looking at Scala, I liked the look of for-comprehensions. They seemed to be a bit like the foreach loops I was used to from Java 5, but with functional rest

5条回答
  •  孤街浪徒
    2021-01-31 20:15

    Please refer to this question. The short answer is that for-comprehensions can be more readable. In particular, if you have many nested generators, the actual scope of what you are doing becomes more clear, and you don't need huge indents.

提交回复
热议问题