Init

init selects all the elements in a Traversable collection but the last one. It can be defined formally as follows:

def init: Traversable[A]  

Let's see an example as follows:

scala> List(1,2,3,4) init
res7: List[Int] = List(1, 2, 3)

In Scala, if you want to select all elements except the first n elements, you should use drop. In the next subsection, we will see how to use drop.

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

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