What will be the result of calling method forall on empty Option?
val a = None

a.forall(_ == "text") 
Explanation
forall is defined in a following way:
final def forall(p: (A) => Boolean): Boolean
Returns true if this Option is empty or the predicate p returns true when applied to this Option's value.

You could rephrase that forall means that none of the elements of the Option violate the given predicate. In case there are no elements, none of them violates it.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Scala quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes