From d05270c93878bdc4d6a85b0578893fe0b94b4a59 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 17 Jun 2009 23:44:24 +0000 Subject: 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.) --- src/library/scala/annotation/experimental.scala | 16 ++++++++++++++++ .../scala/collection/generic/TraversableTemplate.scala | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/library/scala/annotation/experimental.scala (limited to 'src/library') 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 + +/**

+ * An annotation for experimental features. + *

+ */ +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 pf, + * 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 * p. * -- cgit v1.2.3