Warm tip: This article is reproduced from stackoverflow.com, please click
scala scala-collections stream lazylist

What's the difference between LazyList and Stream in Scala?

发布于 2020-04-23 11:59:15

I noticed that Stream is deprecated in Scala 2.13 and they suggest using LazyList. They also say "Use LazyList (which is fully lazy) instead of Stream (which has a lazy tail only)".
What does it exactly mean ? Why did they deprecate Stream ?

Questioner
Michael
Viewed
67
Mario Galic 2020-02-09 01:19

NthPortal, a contributor to LazyList, states in Update and improve LazyList docs #7842

The key difference between LazyList and Stream - and its key feature - is that whether or not it is lazy is evaluated lazily. I'm not sure how best to convey that.

jwvh states in related question

Stream elements are realized lazily except for the 1st (head) element. That was seen as a deficiency.

Scala 2.13 release notes state

immutable.LazyList replaces immutable.Stream. Stream had different laziness behavior and is now deprecated. (#7558, #7000)