I have the following problem in scala. I have to find the first element in al list which satisfies a predicate function with two conditions in OR. The problem is that I would li
def find[T](l1 : List[T], c1 : T => Boolean, c2 : T => Boolean) = ((None : Option[(String, T)]) /: l1)( (l, n) => l match {
case x : Some[_] => l
case x if c1(n) => Some("c1", n)
case x if c2(n) => Some("c2", n)
case _ => None
})
scala> find(l1, c1, c2)
res2: Option[(String, java.lang.String)] = Some((c1,B))
scala> find(l2, c1, c2)
res3: Option[(String, java.lang.String)] = Some((c2,AA))
Depending on your requirements you could have a parameter Map[T => Boolean, String] for the label strings to return: def find[T](l1 : List[T], fs : Map[T => Boolean, String])
or define your own operators.
This will evaluate the whole list where find aborts for the first element found.