Trait/Object

scala.collection.generic

IsTraversableOnce

Related Docs: object IsTraversableOnce | package generic

Permalink

trait IsTraversableOnce[Repr] extends AnyRef

Type class witnessing that a collection representation type Repr has elements of type A and has a conversion to GenTraversableOnce[A].

This type enables simple enrichment of GenTraversableOnces 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: GenTraversableOnce[A]) {
  final def filterMap[B, That](f: A => Option[B])(implicit cbf: CanBuildFrom[Repr, B, That]): That = {
    val b = cbf()
    for(e <- r.seq) f(e) foreach (b +=)
    b.result
  }
}
implicit def filterMap[Repr, A](r: Repr)(implicit fr: IsTraversableOnce[Repr]): FilterMapImpl[fr.A,Repr] =
  new FilterMapImpl[fr.A, Repr](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)
Source
IsTraversableOnce.scala
Since

2.10

Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. IsTraversableOnce
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type A

    Permalink

    The type of elements we can traverse over.

Abstract Value Members

  1. abstract val conversion: (Repr) ⇒ GenTraversableOnce[A]

    Permalink

    A conversion from the representation type Repr to a GenTraversableOnce[A].