summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorJosh Suereth <Joshua.Suereth@gmail.com>2012-07-30 17:31:10 -0700
committerJosh Suereth <Joshua.Suereth@gmail.com>2012-07-30 17:31:10 -0700
commit4f248da9e8c00ea6b75b1042c50335ab53e19ab2 (patch)
tree294b66e7774cdc5439651e1bcc1394d745bf35d0 /src/library
parent3aba55a8a89aec8aaccbdd16047cded02765d8fb (diff)
parent855f01b30b37ee8f07612d8e568eda5d408fd2df (diff)
downloadscala-4f248da9e8c00ea6b75b1042c50335ab53e19ab2.tar.gz
scala-4f248da9e8c00ea6b75b1042c50335ab53e19ab2.tar.bz2
scala-4f248da9e8c00ea6b75b1042c50335ab53e19ab2.zip
Merge pull request #1007 from soc/SI-6064
SI-6064 Add method contains to Option.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/Option.scala9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala
index f651461fe6..2afe2acc13 100644
--- a/src/library/scala/Option.scala
+++ b/src/library/scala/Option.scala
@@ -209,6 +209,15 @@ sealed abstract class Option[+A] extends Product with Serializable {
def withFilter(q: A => Boolean): WithFilter = new WithFilter(x => p(x) && q(x))
}
+ /** Tests whether the option contains a given value as an element.
+ *
+ * @param elem the element to test.
+ * @return `true` if the option has an element that is equal (as
+ * determined by `==`) to `elem`, `false` otherwise.
+ */
+ final def contains[A1 >: A](elem: A1): Boolean =
+ !isEmpty && this.get == elem
+
/** Returns true if this option is nonempty '''and''' the predicate
* $p returns true when applied to this $option's value.
* Otherwise, returns false.