Forall

Forall checks if a predicate holds for each element in a Traversable collection. It can be defined formally as follows:

def forall (p: (A) ⇒ Boolean): Boolean  

Let's see an example as follows:

scala> Vector(1, 2, 8, 10) forall (x => x % 2 == 0)
res2: Boolean = false

While writing Scala code for preprocessing especially, we often need to filter selected data objects. The filter feature of the Scala collection API is used for that. In the next sub-section, we will see an example of using filter.

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

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