summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorjxcoder <jxcoder@ya.ru>2014-07-02 15:33:18 +0700
committerAntoine Gourlay <antoine@gourlay.fr>2014-08-11 17:54:56 +0200
commitf18db59d5c580e4df1ad6bc0fe1206cc00dbce9d (patch)
treecb2f65df8e97f6583fe61e6978690ad8aca9839a /src/library
parentc52bceb15896cc5ec4cb0ec23cb27e656b7d58bd (diff)
downloadscala-f18db59d5c580e4df1ad6bc0fe1206cc00dbce9d.tar.gz
scala-f18db59d5c580e4df1ad6bc0fe1206cc00dbce9d.tar.bz2
scala-f18db59d5c580e4df1ad6bc0fe1206cc00dbce9d.zip
[backport] Added example to Option.collect method.
(cherry picked from commit 6c698089aeb55e649a65dd7ae1bce2b4514ee865)
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/Option.scala11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala
index 905e925f57..5a1c832fae 100644
--- a/src/library/scala/Option.scala
+++ b/src/library/scala/Option.scala
@@ -251,6 +251,17 @@ sealed abstract class Option[+A] extends Product with Serializable {
* nonempty '''and''' `pf` is defined for that value.
* Returns $none otherwise.
*
+ * @example {{{
+ * // Returns Some(HTTP) because the partial function covers the case.
+ * Some("http").collect({case "http" => "HTTP"})
+ *
+ * // Returns None because the partial function doesn't cover the case.
+ * Some("ftp").collect({case "http" => "HTTP"})
+ *
+ * // Returns None because None is passed to the collect method.
+ * None.collect({case value => value})
+ * }}}
+ *
* @param pf the partial function.
* @return the result of applying `pf` to this $option's
* value (if possible), or $none.