Kevin Meredith
Kevin Meredith

Reputation: 41909

Stream v. SeqView

What are use cases to use SeqView over a Stream?

scala> List(1,2).view
res34: scala.collection.SeqView[Int,List[Int]] = SeqView(...)

scala> List(1,2).view.toStream
res33: scala.collection.immutable.Stream[Int] = Stream(1, ?)

Perhaps if you need to access the middle of a Stream and it's costly to access Stream elements, then you'd use the SeqView?

Upvotes: 2

Views: 317

Answers (1)

Lai Yu-Hsuan
Lai Yu-Hsuan

Reputation: 28121

SeqView is not cheaper than Stream. In fact, it's more costly to access an element in SeqView than Stream, because Stream caches the results it computed but SeqView(or any other Views) not.

Upvotes: 2

Related Questions