2

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?

Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
  • This is nearly a duplicate of this question: http://stackoverflow.com/questions/5159000/stream-vs-views-vs-iterators – wheaties Dec 23 '13 at 16:38
  • Also see: http://stackoverflow.com/questions/4798043/what-is-the-difference-between-the-methods-iterator-and-view and http://stackoverflow.com/questions/3361478/what-are-views-for-collections-and-when-would-you-want-to-use-them – wheaties Dec 23 '13 at 16:40
  • thanks - I'll delete this question – Kevin Meredith Dec 23 '13 at 16:41
  • View is broken, don't use it. [Point.](https://groups.google.com/d/msg/scala-language/uRt7Nvj3o6k/ufiCOr47aDAJ) – kiritsuku Dec 23 '13 at 16:41
  • @Kevin Meredith Nah, this question and the answer do give a nice, concise response to what you proposed. – wheaties Dec 23 '13 at 16:42

1 Answers1

2

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.

Lai Yu-Hsuan
  • 27,509
  • 28
  • 97
  • 164