diff options
-rw-r--r-- | sources/scala/List.scala | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/sources/scala/List.scala b/sources/scala/List.scala index 79d182bff2..ddc2570225 100644 --- a/sources/scala/List.scala +++ b/sources/scala/List.scala @@ -174,6 +174,11 @@ trait List[+a] extends Seq[a] { def exists(p: a => Boolean): Boolean = !isEmpty && (p(head) || tail.exists(p)); + def find(p: a => Boolean): Option[a] = match { + case Nil => None + case x :: xs => if (p(x)) Some(x) else xs.find(p) + } + /** Combines the elements of this list together using the binary * operator <code>op</code>, from left to right, and starting with * the value <code>z</code>. Similar to <code>fold</code> but with |