Scala 中的 LazyList 和 Stream 有什么区别?

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

我注意到 StreamScala 2.13 中被弃用,他们建议使用 LazyList。 他们还说 "Use LazyList (which is fully lazy) instead of Stream (which has a lazy tail only)".
这到底是什么意思?他们为什么弃用 Stream

NthPortal,LazyList 的贡献者,在 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 在

中指出

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

Scala 2.13 发行说明state

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

根据 blog post:

LazyList Is Preferred Over Stream

Stream is deprecated in favor of LazyList. As its name suggests, a LazyList is a linked list whose elements are lazily evaluated. An important semantic difference with Stream is that in LazyList both the head and the tail are lazy, whereas in Stream only the tail is lazy.

也在Stream documentation:

Deprecated (Since version 2.13.0)

Use LazyList (which is fully lazy) instead of Stream (which has a lazy tail only)