Skip to content

Instantly share code, notes, and snippets.

@tomjadams
Created August 20, 2008 06:14
Show Gist options
  • Save tomjadams/6326 to your computer and use it in GitHub Desktop.
Save tomjadams/6326 to your computer and use it in GitHub Desktop.
scala> val list = List(1, 2, 3, 4, 5, 6, 7, 8, 9)
list: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)
scala> val iter = list.elements
iter: Iterator[Int] = non-empty iterator
scala> val firstTwoElements = iter.filter(_ < 5).zipWithIndex.takeWhile(_._2 < 2).map(_._1).toList
firstTwoElements: List[Int] = List(1, 2)
scala> assert(iter.toList == List(3, 4, 5, 6, 7, 8, 9))
java.lang.AssertionError: assertion failed
at scala.Predef$.assert(Predef.scala:87)
at .<init>(<console>:7)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:3)
at RequestResult$.<clinit>(<console>)
at RequestResult$result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j...
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment