summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/generic
diff options
context:
space:
mode:
authorAlexander Clare <alexander.clare@gmail.com>2012-07-16 13:35:43 -0500
committerAlexander Clare <alexander.clare@gmail.com>2012-07-16 14:36:19 -0500
commit41869c39ba68ef574595533777d2a99fcabdbdc3 (patch)
tree862185c349c54dc1e96e8cfb59b96ac52ac3515b /src/library/scala/collection/generic
parentab0e09bb44567a19690529c03cb388295ce5d338 (diff)
downloadscala-41869c39ba68ef574595533777d2a99fcabdbdc3.tar.gz
scala-41869c39ba68ef574595533777d2a99fcabdbdc3.tar.bz2
scala-41869c39ba68ef574595533777d2a99fcabdbdc3.zip
Changes suggested by @retronym and @jsuereth
Change return type to case classes, branch between functions depending on IndexedSeq instead of IndexedSeqLike, and alter tests accordingly. Clean up doc comments and reflect changes in them.
Diffstat (limited to 'src/library/scala/collection/generic')
-rw-r--r--src/library/scala/collection/generic/IsSeqLike.scala21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/library/scala/collection/generic/IsSeqLike.scala b/src/library/scala/collection/generic/IsSeqLike.scala
index 47e2924d34..8eac025ed6 100644
--- a/src/library/scala/collection/generic/IsSeqLike.scala
+++ b/src/library/scala/collection/generic/IsSeqLike.scala
@@ -10,8 +10,27 @@ package scala.collection
package generic
/** Type class witnessing that a collection representation type `Repr` has
- * elements of type `A` and has a conversion to `SeqLike[A, Repr]`.
+ * elements of type `A` and has a conversion to `SeqLike[A, Repr]`.
*
+ * This type enables simple enrichment of `Seq`s with extension methods which
+ * can make full use of the mechanics of the Scala collections framework in
+ * their implementation.
+ *
+ * Example usage:
+ * {{{
+ * class FilterMapImpl[A, Repr](val r: SeqLike[A, Repr]) {
+ * final def filterMap[B, That](f: A => Option[B])(implicit cbf: CanBuildFrom[Repr, B, That]): That =
+ * r.flatMap(f(_))
+ * }
+ * implicit def filterMap[Repr, A](r: Repr)(implicit fr: IsSeqLike[Repr]): FilterMapImpl[fr.A,Repr] =
+ * new FilterMapImpl(fr.conversion(r))
+ *
+ * val l = List(1, 2, 3, 4, 5)
+ * List(1, 2, 3, 4, 5) filterMap (i => if(i % 2 == 0) Some(i) else None)
+ * // == List(2, 4)
+ * }}}
+ *
+ * @see [[scala.collection.generic.Seq]]
* @see [[scala.collection.generic.IsTraversableLike]]
*/
trait IsSeqLike[Repr] {