Skip to content

Instantly share code, notes, and snippets.

@shehaaz
Last active July 29, 2016 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shehaaz/a1db0efb7b944ea424c443992bd92c3b to your computer and use it in GitHub Desktop.
Save shehaaz/a1db0efb7b944ea424c443992bd92c3b to your computer and use it in GitHub Desktop.
What is a SeqView in Scala
scala> val seq = (1 to 10000000).view.filter(_ % 2 == 0).map(x => x+1)
seq: scala.collection.SeqView[Int,Seq[_]] = SeqViewFM(...)
scala> seq.take(10)
res0: scala.collection.SeqView[Int,Seq[_]] = SeqViewFMS(...)
scala> seq.take(10).force
res1: Seq[Int] = Vector(3, 5, 7, 9, 11, 13, 15, 17, 19, 21)
scala> val seq = (1 to 10000000).filter(_ % 2 == 0).map(x => x+1)
java.lang.OutOfMemoryError: Java heap space
at java.lang.Integer.valueOf(Integer.java:832)
at scala.runtime.BoxesRunTime.boxToInteger(BoxesRunTime.java:65)
at $anonfun$2.apply(<console>:10)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.Iterator$class.foreach(Iterator.scala:742)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1194)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
... 21 elided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment