Drop

drop is used to select all elements except the first n elements. It can be defined formally as follows:

def drop(n: Int): Traversable[A]  

Let's see an example as follows:

// Drop the first three elements
scala> List(1,2,3,4) drop 3
res8: List[Int] = List(4)

In Scala, if you want take a set of elements until a predicate is satisfied, you should use takeWhile. In the next subsection, we will see how to use takeWhile.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.204.7