diff options
author | Matthias Zenger <mzenger@gmail.com> | 2003-06-05 10:02:34 +0000 |
---|---|---|
committer | Matthias Zenger <mzenger@gmail.com> | 2003-06-05 10:02:34 +0000 |
commit | be858b38fe6527378948ad94b1db9e11143bcdfa (patch) | |
tree | 6193bcd6bf780bf735b3482f0511e858da2e49eb /sources | |
parent | c481e95b2f3d0a8cc98b106c971506e102702d06 (diff) | |
download | scala-be858b38fe6527378948ad94b1db9e11143bcdfa.tar.gz scala-be858b38fe6527378948ad94b1db9e11143bcdfa.tar.bz2 scala-be858b38fe6527378948ad94b1db9e11143bcdfa.zip |
Added a find method.
Diffstat (limited to 'sources')
-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 |