my Haskell* is a bit rusty, so i can imagine that I’m missing the obvious:
def any[A](s: Traversable[A], f: A => Boolean): Boolean = {
s.foldLeft(false)((bool, elem) => bool || f(elem))
}
Does one of these properties apply to the it?
- predefined somewhere in the Scala libs
- circumstantial, and faster written as some one-liner
- wrong (I didn’t test it, sorry ;))
*actually SML, but that’s 99% the same, but known by nobody under the sun.
It’s predefined and is called
exists. Andforallwould be the “all” function you are looking for.You can make it more performant using a
forloop with abreak(fromscala.util.control.Breaks). (See the standard library implementation ofexistsandforall.)It’s correct.