A mixin trait that implements index flag behaviour using atomic integers.
A mixin trait that implements index flag behaviour using atomic integers.
The setIndex
operation is wait-free, while conditional set operations setIndexIfGreater
and setIndexIfLesser
are lock-free and support only monotonic changes.
A base trait for builder factories.
A base trait for builder factories.
the type of the underlying collection that requests a builder to be created.
the element type of the collection to be created.
the type of the collection to be created.
2.8
A base trait for parallel builder factories.
A base trait for parallel builder factories.
the type of the underlying collection that requests a builder to be created.
the element type of the collection to be created.
the type of the collection to be created.
2.8
A template for companion objects of ClassTagTraversable
and
subclasses thereof.
This trait forms part of collections that can be cleared with a clear() call.
This trait forms part of collections that can be cleared with a clear() call.
2.10
2.10
This signalling implementation returns default values and ignores received signals.
Class implementing delegated signalling.
An implementation of the signalling interface using delegates.
A template trait that contains just the map
, flatMap
, foreach
and withFilter
methods
of trait TraversableLike
.
A template for companion objects of Map
and subclasses thereof.
A template for companion objects of Seq and subclasses thereof.
A template for companion objects of Seq and subclasses thereof.
2.8
A template for companion objects of Set
and subclasses thereof.
A template for companion objects of Traversable
and subclasses thereof.
A template for companion objects of Traversable
and subclasses thereof.
This class provides a set of operations to create
objects.
It is typically inherited by companion objects of subclasses of Traversable
Traversable
.
2.8
This class represents companions of classes which require ClassTags for their element types.
This trait represents collections classes which require class tags for their element types.
This trait represents collections classes which require class tags for their element types.
2.8
A template class for companion objects of "regular" collection classes represent an unconstrained higher-kinded type.
A template class for companion objects of "regular" collection classes
represent an unconstrained higher-kinded type. Typically
such classes inherit from trait GenericTraversableTemplate
.
The type constructor representing the collection class.
2.8
This class represents companions of classes which require the ordered trait for their element types.
This class represents companions of classes which require the ordered trait for their element types.
2.8
This trait represents collections classes which require ordered element types.
A template class for companion objects of parallel collection classes.
A template class for companion objects of parallel collection classes.
They should be mixed in together with GenericCompanion
type.
A template trait for collections having a companion.
A template trait for collections having a companion.
the element type of the collection
the type constructor representing the collection class
2.8
2.8
A template class for companion objects of
collection classes
that represent an unconstrained higher-kinded type.regular
A template class for companion objects of
collection classes
that represent an unconstrained higher-kinded type.
regular
The type of the collection elements.
The type constructor representing the collection class.
2.8
This trait forms part of collections that can be augmented
using a +=
operator and that can be cleared of all elements using
a clear
method.
This trait forms part of collections that can be augmented
using a +=
operator and that can be cleared of all elements using
a clear
method.
2.8
2.8
2.8
A template for companion objects of immutable.Map
and subclasses thereof.
A template for companion objects of immutable.Map
and subclasses thereof.
2.8
2.8
A template for companion objects of SortedMap
and subclasses thereof.
A template for companion objects of SortedMap
and subclasses thereof.
2.8
A template for companion objects of SortedSet
and subclasses thereof.
A template for companion objects of SortedSet
and subclasses thereof.
2.8
A template for companion objects of IndexedSeq and subclasses thereof.
A template for companion objects of IndexedSeq and subclasses thereof.
2.11
Type class witnessing that a collection representation type Repr
has
elements of type A
and has a conversion to SeqLike[A, Repr]
.
Type class witnessing that a collection representation type Repr
has
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)
A trait which can be used to avoid code duplication when defining extension
methods that should be applicable both to existing Scala collections (i.e.,
types extending GenTraversableLike
) as well as other (potentially user-defined)
types that could be converted to a Scala collection type.
A trait which can be used to avoid code duplication when defining extension
methods that should be applicable both to existing Scala collections (i.e.,
types extending GenTraversableLike
) as well as other (potentially user-defined)
types that could be converted to a Scala collection type. This trait
makes it possible to treat Scala collections and types that can be implicitly
converted to a collection type uniformly. For example, one can provide
extension methods that work both on collection types and on String
s (String
s
do not extend GenTraversableLike
, but can be converted to GenTraversableLike
)
IsTraversable
provides two members:
A
, which represents the element type of the target GenTraversableLike[A, Repr]
conversion
, which provides a way to convert between the type we wish to add extension methods to, Repr
, and GenTraversableLike[A, Repr]
.One must provide IsTraversableLike
as an implicit parameter type of an implicit
conversion. Its usage is shown below. Our objective in the following example
is to provide a generic extension method mapReduce
to any type that extends
or can be converted to GenTraversableLike
. In our example, this includes
String
.
import scala.collection.GenTraversableLike import scala.collection.generic.IsTraversableLike class ExtensionMethods[A, Repr](coll: GenTraversableLike[A, Repr]) { def mapReduce[B](mapper: A => B)(reducer: (B, B) => B): B = { val iter = coll.toIterator var res = mapper(iter.next()) while (iter.hasNext) res = reducer(res, mapper(iter.next())) res } } implicit def withExtensions[Repr](coll: Repr)(implicit traversable: IsTraversableLike[Repr]) = new ExtensionMethods(traversable.conversion(coll)) // See it in action! List(1, 2, 3).mapReduce(_ * 2)(_ + _) // res0: Int = 12 "Yeah, well, you know, that's just, like, your opinion, man.".mapReduce(x => 1)(_ + _) // res1: Int = 59
Here, we begin by creating a class ExtensionMethods
which contains our
mapReduce
extension method. Note that ExtensionMethods
takes a constructor
argument coll
of type GenTraversableLike[A, Repr]
, where A
represents the
element type and Repr
represents (typically) the collection type. The
implementation of mapReduce
itself is straightforward.
The interesting bit is the implicit conversion withExtensions
, which
returns an instance of ExtensionMethods
. This implicit conversion can
only be applied if there is an implicit value traversable
of type
IsTraversableLike[Repr]
in scope. Since IsTraversableLike
provides
value member conversion
, which gives us a way to convert between whatever
type we wish to add an extension method to (in this case, Repr
) and
GenTraversableLike[A, Repr]
, we can now convert coll
from type Repr
to GenTraversableLike[A, Repr]
. This allows us to create an instance of
the ExtensionMethods
class, which we pass our new
GenTraversableLike[A, Repr]
to.
When the mapReduce
method is called on some type of which it is not
a member, implicit search is triggered. Because implicit conversion
withExtensions
is generic, it will be applied as long as an implicit
value of type IsTraversableLike[Repr]
can be found. Given that
IsTraversableLike
contains implicit members that return values of type
IsTraversableLike
, this requirement is typically satisfied, and the chain
of interactions described in the previous paragraph is set into action.
(See the IsTraversableLike
companion object, which contains a precise
specification of the available implicits.)
Note: Currently, it's not possible to combine the implicit conversion and the class with the extension methods into an implicit class due to limitations of type inference.
IsTraversableLike
for New TypesOne must simply provide an implicit value of type IsTraversableLike
specific to the new type, or an implicit conversion which returns an
instance of IsTraversableLike
specific to the new type.
Below is an example of an implementation of the IsTraversableLike
trait
where the Repr
type is String
.
implicit val stringRepr: IsTraversableLike[String] { type A = Char } = new IsTraversableLike[String] { type A = Char val conversion = implicitly[String => GenTraversableLike[Char, String]] }
2.10
Type class witnessing that a collection representation type Repr
has
elements of type A
and has a conversion to GenTraversableOnce[A]
.
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 GenTraversableOnce
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: 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)
2.10
A template for companion objects of Map
and subclasses thereof.
A template for companion objects of mutable.Map
and subclasses thereof.
A template for companion objects of mutable.Map
and subclasses thereof.
2.8
2.8
A template class for companion objects of ParIterable
and subclasses
thereof.
A template class for companion objects of ParIterable
and subclasses
thereof. This class extends TraversableFactory
and provides a set of
operations to create
objects.ParIterable
A template class for companion objects of ParMap
and subclasses thereof.
A template class for companion objects of ParMap
and subclasses thereof.
This class extends TraversableFactory
and provides a set of operations
to create
objects.ParMap
2.8
A template for companion objects of Seq and subclasses thereof.
A template for companion objects of Seq and subclasses thereof.
2.8
This trait forms part of collections that can be reduced
using a -=
operator.
This trait forms part of collections that can be reduced
using a -=
operator.
2.8
2.8
A message interface serves as a unique interface to the part of the collection capable of receiving messages from a different task.
A message interface serves as a unique interface to the part of the collection capable of receiving messages from a different task.
One example of use of this is the find
method, which can use the
signalling interface to inform worker threads that an element has
been found and no further search is necessary.
A trait for objects which have a size.
Any collection (including maps) whose keys (or elements) are ordered.
Any collection (including maps) whose keys (or elements) are ordered.
2.8
A template for companion objects of mutable.Map and subclasses thereof.
A template for companion objects of mutable.Map and subclasses thereof.
2.8
A template for companion objects of Set and subclasses thereof.
A template for companion objects of Set and subclasses thereof.
2.8
This trait represents collection-like objects that can be reduced using a '+' operator.
This trait represents collection-like objects that can be reduced
using a '+' operator. It defines variants of -
and --
as convenience methods in terms of single-element removal -
.
the type of the elements of the collection.
the type of the collection itself
2.8
2.8
Class implementing delegated signalling, but having its own distinct tag
.
A template for companion objects of Traversable
and subclasses thereof.
A template for companion objects of Traversable
and subclasses thereof.
This class provides a set of operations to create Traversable
objects.
It is typically inherited by companion objects of subclasses of Traversable
.
2.8
A mixin trait that implements abort flag behaviour using volatile variables.
(Since version 2.10.0) use ClassTagTraversableFactory instead
(Since version 2.10.0) use GenericClassTagCompanion instead
(Since version 2.10.0) use GenericClassTagTraversableTemplate instead
This trait implements a forwarder for iterable objects.
This trait implements a forwarder for iterable objects. It forwards all calls to a different iterable object, except for
toString
, hashCode
, equals
, stringPrefix
newBuilder
, view
The above methods are forwarded by subclass `IterableProxy`.
(Since version 2.11.0) Forwarding is inherently unreliable since it is not automated and methods can be forgotten.
2.8
2.8
This class implements a forwarder for sequences.
This class implements a forwarder for sequences. It forwards all calls to a different sequence object except for
toString
, hashCode
, equals
, stringPrefix
newBuilder
, view
, toSeq
The above methods are forwarded by subclass SeqProxy
.
(Since version 2.11.0) Forwarding is inherently unreliable since it is not automated and new methods can be forgotten.
2.8
2.8
This trait implements a forwarder for traversable objects.
This trait implements a forwarder for traversable objects. It forwards all calls to a different traversable, except for:
toString
, hashCode
, equals
, stringPrefix
newBuilder
, view
All calls creating a new traversable of the same kind.
(Since version 2.11.0) Forwarding is inherently unreliable since it is not automated and new methods can be forgotten.
2.8
2.8
An object that returns default values and ignores received signals.