-
It’s predefined and is called
exists. Andforallwould be the “all” function you are looking for.scala> Vector(3, 4, 5).exists(_ % 2 == 0) res1: Boolean = true scala> Vector(3, 4, 5).forall(_ % 2 == 0) res2: Boolean = false -
You can make it more performant using a
forloop with abreak(fromscala.util.control.Breaks). (See the standard library implementation ofexistsandforall.) -
It’s correct.