LinearSeq Iterator

I cannot find a Scala collection that is a subtype of LinearSeq, and that gets recomputed each time it is accessed…

It would be similar to LazyList, except without memoization. It would also be similar to Iterator, but with the ability to take the head and tail, and to prepend a new element.

Am I missing something?

It seems fs2 Stream is what you want.

1 Like

scala.collection.View probably does everything you asked, except that it’s not a subtype of LinearSeq.

The only thing that is not completely straightforward is prepending. There is a Prepended implementation of View, but for some reason there is no prepend operation that actually uses that class… So you can do View(x) ++ view or perhaps call Prepended(x, view) directly.

1 Like

Do you mean this? Hmm, it seems to be a completely separate system from the Scala standard library. It doesn’t extend LinearSeq, or even Seq.

It does look really nice. But I just want something simple right now, rather than having to learn a new language and rewrite all my code.

Yeah, I saw that View is not a subtype of LinearSeq. This, and particularly the lack of +: is a deal breaker for me.

It is odd that the standard library is missing what is arguably one of the simplest and most natural collection types.