summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Zenger <mzenger@gmail.com>2003-06-05 10:02:34 +0000
committerMatthias Zenger <mzenger@gmail.com>2003-06-05 10:02:34 +0000
commitbe858b38fe6527378948ad94b1db9e11143bcdfa (patch)
tree6193bcd6bf780bf735b3482f0511e858da2e49eb
parentc481e95b2f3d0a8cc98b106c971506e102702d06 (diff)
downloadscala-be858b38fe6527378948ad94b1db9e11143bcdfa.tar.gz
scala-be858b38fe6527378948ad94b1db9e11143bcdfa.tar.bz2
scala-be858b38fe6527378948ad94b1db9e11143bcdfa.zip
Added a find method.
-rw-r--r--sources/scala/List.scala5
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