Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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>
Add Comment
Please, Sign In to add comment