Use-cases for Streams in Scala

后端 未结 4 1467
孤街浪徒
孤街浪徒 2020-12-12 13:18

In Scala there is a Stream class that is very much like an iterator. The topic Difference between Iterator and Stream in Scala? offers some insights into the similarities a

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 13:53

    Stream is to Iterator as immutable.List is to mutable.List. Favouring immutability prevents a class of bugs, occasionally at the cost of performance.

    scalac itself isn't immune to these problems: http://article.gmane.org/gmane.comp.lang.scala.internals/2831

    As Daniel points out, favouring laziness over strictness can simplify algorithms and make it easier to compose them.

提交回复
热议问题