In this section, we are going to illustrate how the manipulation of collections in Scala can be expressed in a concise and expressive way.
The REPL is a great tool to try out the powerful operations that we can apply to the collection elements. Let's go back to our interpreter prompt:
scala> val numbers = List(1,2,3,4,5,6) numbers: List[Int] = List(1,2,3,4,5,6) scala> val reversedList = numbers.reverse reversedList: List[Int] = List(6,5,4,3,2,1) scala> val onlyAFew = numbers drop 2 take 3 onlyAFew: List[Int] = List(3, 4, 5)
drop method indicates that we get rid of the first two elements of the list, and the
take method indicates that we keep only three elements from ...