diff options
author | Paul Phillips <paulp@improving.org> | 2009-06-17 23:44:24 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-06-17 23:44:24 +0000 |
commit | d05270c93878bdc4d6a85b0578893fe0b94b4a59 (patch) | |
tree | e8e932a22c5ee04f10fc30e154e6326fd9f7b8a5 | |
parent | e58673295a780ab7e9e2098a907df3466866a300 (diff) | |
download | scala-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.)
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Definitions.scala | 1 | ||||
-rw-r--r-- | src/library/scala/annotation/experimental.scala | 16 | ||||
-rw-r--r-- | src/library/scala/collection/generic/TraversableTemplate.scala | 14 |
3 files changed, 31 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index ad0efdec11..af158f27d4 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -170,6 +170,7 @@ trait Definitions { lazy val UncheckedClass: Symbol = getClass("scala.unchecked") lazy val TailrecClass: Symbol = getClass("scala.annotation.tailrec") lazy val SwitchClass: Symbol = getClass("scala.annotation.switch") + lazy val ExperimentalClass: Symbol = getClass("scala.annotation.experimental") var EqualsPatternClass: Symbol = _ 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>. * |