From 0891a46d960c4f1803541ce28eee7ec54b5b00ea Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 13 Oct 2010 06:52:30 +0000 Subject: 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. --- src/library/scala/Option.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') 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. */ -- cgit v1.2.3