Reputation: 41909
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
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 View
s) not.
Upvotes: 2