summaryrefslogtreecommitdiff
path: root/src/library/scala/Option.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-10-13 06:52:30 +0000
committerPaul Phillips <paulp@improving.org>2010-10-13 06:52:30 +0000
commit0891a46d960c4f1803541ce28eee7ec54b5b00ea (patch)
tree2368b47c948a0165e72d5b5077bb2e10b051e930 /src/library/scala/Option.scala
parentd64cbe436646bccb42def34641c399e8367b1e44 (diff)
downloadscala-0891a46d960c4f1803541ce28eee7ec54b5b00ea.tar.gz
scala-0891a46d960c4f1803541ce28eee7ec54b5b00ea.tar.bz2
scala-0891a46d960c4f1803541ce28eee7ec54b5b00ea.zip
Added filterNot to Option so I can stop being d...
Added filterNot to Option so I can stop being driven mad by this difference. scala> Some(5) filter (_ > 2) res0: Option[Int] = Some(5) scala> Some(5) filterNot (_ < 2) res1: Iterable[Int] = List(5) No review.
Diffstat (limited to 'src/library/scala/Option.scala')
-rw-r--r--src/library/scala/Option.scala13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala
index bd15c31609..e853c0ea45 100644
--- a/src/library/scala/Option.scala
+++ b/src/library/scala/Option.scala
@@ -69,6 +69,11 @@ object Option {
* }
* }}}
*
+ * @note Many of the methods in here are duplicative with those
+ * in the Traversable hierarchy, but they are duplicated for a reason:
+ * the implicit conversion tends to leave one with an Iterable in
+ * situations where one could have retained an Option.
+ *
* @author Martin Odersky
* @author Matthias Zenger
* @version 1.1, 16/01/2007
@@ -149,6 +154,14 @@ sealed abstract class Option[+A] extends Product {
def filter(p: A => Boolean): Option[A] =
if (isEmpty || p(this.get)) this else None
+ /** Returns this $option if it is nonempty '''and''' applying the predicate $p to
+ * this $option's value returns false. Otherwise, return $none.
+ *
+ * @param p the predicate used for testing.
+ */
+ def filterNot(p: A => Boolean): Option[A] =
+ if (isEmpty || !p(this.get)) this else None
+
/** Necessary to keep $option from being implicitly converted to
* [[scala.collection.Iterable]] in `for` comprehensions.
*/