summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-06-17 23:44:24 +0000
committerPaul Phillips <paulp@improving.org>2009-06-17 23:44:24 +0000
commitd05270c93878bdc4d6a85b0578893fe0b94b4a59 (patch)
treee8e932a22c5ee04f10fc30e154e6326fd9f7b8a5 /src/library
parente58673295a780ab7e9e2098a907df3466866a300 (diff)
downloadscala-d05270c93878bdc4d6a85b0578893fe0b94b4a59.tar.gz
scala-d05270c93878bdc4d6a85b0578893fe0b94b4a59.tar.bz2
scala-d05270c93878bdc4d6a85b0578893fe0b94b4a59.zip
Adds @experimental annotation to lower the acti...
Adds @experimental annotation to lower the activation energy wall between me and all my good ideas. Then took advantage of same to add the experimental filterMap to Traversable. (I consider its goodness undeniable, but its name at least is experimental.)
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/annotation/experimental.scala16
-rw-r--r--src/library/scala/collection/generic/TraversableTemplate.scala14
2 files changed, 30 insertions, 0 deletions
diff --git a/src/library/scala/annotation/experimental.scala b/src/library/scala/annotation/experimental.scala
new file mode 100644
index 0000000000..b33d9ea246
--- /dev/null
+++ b/src/library/scala/annotation/experimental.scala
@@ -0,0 +1,16 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2009, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+package scala.annotation
+
+/** <p>
+ * An annotation for experimental features.
+ * </p>
+ */
+final class experimental(message: String) extends StaticAnnotation {
+ def this() = this("")
+} \ No newline at end of file
diff --git a/src/library/scala/collection/generic/TraversableTemplate.scala b/src/library/scala/collection/generic/TraversableTemplate.scala
index 64017b06aa..e053ab4cb4 100644
--- a/src/library/scala/collection/generic/TraversableTemplate.scala
+++ b/src/library/scala/collection/generic/TraversableTemplate.scala
@@ -13,6 +13,7 @@ package scala.collection.generic
// import immutable.{List, Stream, Nil} //!!!
import mutable.{Buffer, ArrayBuffer, ListBuffer}
+import annotation.experimental
/** A template trait for traversable collections.
* This is a base trait of all kinds of Scala collections. It implements
@@ -180,6 +181,19 @@ self =>
b.result
}
+ /** Returns a new traversable based on the partial function <code>pf</code>,
+ * containing pf(x) for all the elements which are defined on pf.
+ * The order of the elements is preserved.
+ * @param pf the partial function which filters and maps the traversable.
+ * @return the new traversable.
+ */
+ @experimental
+ def filterMap[B, That](pf: PartialFunction[Any, B])(implicit bf: BuilderFactory[B, That, This]): That = {
+ val b = bf(thisCollection)
+ for (x <- this) if (pf.isDefinedAt(x)) b += pf(x)
+ b.result
+ }
+
/** Returns a traversable with all elements of this traversable which do not satisfy the predicate
* <code>p</code>.
*