collectFirst
trait Collection[A] {
def collectFirst[B](f: PartialFunction[A, B]): Option[B]
}
collectFirst
applies the partial function f
to the first element in this collection for which f
is defined and returns its result wrapped with Some
.
If the partial function f
is not defined for any element in this collection then None
is returned.