package generic
- Source
- package.scala
- Alphabetic
- By Inheritance
- generic
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
AtomicIndexFlag extends Signalling
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 operationssetIndexIfGreater
andsetIndexIfLesser
are lock-free and support only monotonic changes. - trait BitSetFactory[Coll <: BitSet with BitSetLike[Coll]] extends AnyRef
- type CanBuild[-Elem, +To] = CanBuildFrom[Nothing, Elem, To]
-
trait
CanBuildFrom[-From, -Elem, +To] extends AnyRef
A base trait for builder factories.
A base trait for builder factories.
- From
the type of the underlying collection that requests a builder to be created.
- Elem
the element type of the collection to be created.
- To
the type of the collection to be created.
- Annotations
- @implicitNotFound( msg = ... )
- Since
2.8
- See also
-
trait
CanCombineFrom[-From, -Elem, +To] extends CanBuildFrom[From, Elem, To] with Parallel
A base trait for parallel builder factories.
A base trait for parallel builder factories.
- From
the type of the underlying collection that requests a builder to be created.
- Elem
the element type of the collection to be created.
- To
the type of the collection to be created.
- Since
2.8
-
abstract
class
ClassTagTraversableFactory[CC[X] <: Traversable[X] with GenericClassTagTraversableTemplate[X, CC]] extends GenericClassTagCompanion[CC]
A template for companion objects of
ClassTagTraversable
and subclasses thereof. -
trait
Clearable extends AnyRef
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.
- Since
2.10
-
class
DefaultSignalling extends Signalling with VolatileAbort
This signalling implementation returns default values and ignores received signals.
-
class
DelegatedContext extends DelegatedSignalling
Class implementing delegated signalling.
-
trait
DelegatedSignalling extends Signalling
An implementation of the signalling interface using delegates.
-
trait
FilterMonadic[+A, +Repr] extends Any
A template trait that contains just the
map
,flatMap
,foreach
andwithFilter
methods of traitTraversableLike
. -
abstract
class
GenMapFactory[CC[A, B] <: GenMap[A, B] with GenMapLike[A, B, CC[A, B]]] extends AnyRef
A template for companion objects of
Map
and subclasses thereof. -
abstract
class
GenSeqFactory[CC[X] <: GenSeq[X] with GenericTraversableTemplate[X, CC]] extends GenTraversableFactory[CC]
A template for companion objects of Seq and subclasses thereof.
A template for companion objects of Seq and subclasses thereof.
- Since
2.8
-
abstract
class
GenSetFactory[CC[X] <: GenSet[X] with GenSetLike[X, CC[X]]] extends GenericCompanion[CC]
A template for companion objects of
Set
and subclasses thereof. -
abstract
class
GenTraversableFactory[CC[X] <: GenTraversable[X] with GenericTraversableTemplate[X, CC]] extends GenericCompanion[CC]
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 ofTraversable
Traversable
.- Since
2.8
-
abstract
class
GenericClassTagCompanion[+CC[X] <: Traversable[X]] extends AnyRef
This class represents companions of classes which require ClassTags for their element types.
-
trait
GenericClassTagTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBuilder[A, CC[A]]
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.
- Since
2.8
-
abstract
class
GenericCompanion[+CC[X] <: GenTraversable[X]] extends AnyRef
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
.- CC
The type constructor representing the collection class.
- Since
2.8
- See also
-
abstract
class
GenericOrderedCompanion[+CC[X] <: Traversable[X]] extends AnyRef
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.
- Since
2.8
-
trait
GenericOrderedTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBuilder[A, CC[A]]
This trait represents collections classes which require ordered element types.
-
trait
GenericParCompanion[+CC[X] <: ParIterable[X]] extends AnyRef
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. - trait GenericParMapCompanion[+CC[P, Q] <: ParMap[P, Q]] extends AnyRef
- trait GenericParMapTemplate[K, +V, +CC[X, Y] <: ParMap[X, Y]] extends GenericParTemplate[(K, V), ParIterable]
-
trait
GenericParTemplate[+A, +CC[X] <: ParIterable[X]] extends GenericTraversableTemplate[A, CC] with HasNewCombiner[A, CC[A]]
A template trait for collections having a companion.
A template trait for collections having a companion.
- A
the element type of the collection
- CC
the type constructor representing the collection class
- Since
2.8
- trait GenericSeqCompanion[CC[X] <: Traversable[X]] extends GenericCompanion[CC]
-
trait
GenericSetTemplate[A, +CC[X] <: GenSet[X]] extends GenericTraversableTemplate[A, CC]
- Since
2.8
-
trait
GenericTraversableTemplate[+A, +CC[X] <: GenTraversable[X]] extends HasNewBuilder[A, CC[A]]
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
- A
The type of the collection elements.
- CC
The type constructor representing the collection class.
- Since
2.8
-
trait
Growable[-A] extends Clearable
This trait forms part of collections that can be augmented using a
+=
operator and that can be cleared of all elements using aclear
method.This trait forms part of collections that can be augmented using a
+=
operator and that can be cleared of all elements using aclear
method.- Since
2.8
- trait HasNewBuilder[+A, +Repr] extends Any
-
trait
HasNewCombiner[+T, +Repr] extends AnyRef
- Since
2.8
-
abstract
class
ImmutableMapFactory[CC[A, +B] <: immutable.Map[A, B] with immutable.MapLike[A, B, CC[A, B]]] extends MapFactory[CC]
A template for companion objects of
immutable.Map
and subclasses thereof.A template for companion objects of
immutable.Map
and subclasses thereof.- Since
2.8
- abstract class ImmutableSetFactory[CC[X] <: immutable.Set[X] with SetLike[X, CC[X]]] extends SetFactory[CC]
-
abstract
class
ImmutableSortedMapFactory[CC[A, B] <: immutable.SortedMap[A, B] with SortedMapLike[A, B, CC[A, B]]] extends SortedMapFactory[CC]
A template for companion objects of
SortedMap
and subclasses thereof.A template for companion objects of
SortedMap
and subclasses thereof.- Since
2.8
-
abstract
class
ImmutableSortedSetFactory[CC[A] <: immutable.SortedSet[A] with SortedSetLike[A, CC[A]]] extends SortedSetFactory[CC]
A template for companion objects of
SortedSet
and subclasses thereof.A template for companion objects of
SortedSet
and subclasses thereof.- Since
2.8
-
abstract
class
IndexedSeqFactory[CC[X] <: IndexedSeq[X] with GenericTraversableTemplate[X, CC]] extends SeqFactory[CC]
A template for companion objects of IndexedSeq and subclasses thereof.
A template for companion objects of IndexedSeq and subclasses thereof.
- Since
2.11
-
trait
IsSeqLike[Repr] extends AnyRef
Type class witnessing that a collection representation type
Repr
has elements of typeA
and has a conversion toSeqLike[A, Repr]
.Type class witnessing that a collection representation type
Repr
has elements of typeA
and has a conversion toSeqLike[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)
-
trait
IsTraversableLike[Repr] extends AnyRef
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 onString
s (String
s do not extendGenTraversableLike
, but can be converted toGenTraversableLike
)IsTraversable
provides two members:- type member
A
, which represents the element type of the targetGenTraversableLike[A, Repr]
- value member
conversion
, which provides a way to convert between the type we wish to add extension methods to,Repr
, andGenTraversableLike[A, Repr]
.
Usage
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 methodmapReduce
to any type that extends or can be converted toGenTraversableLike
. In our example, this includesString
.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 ourmapReduce
extension method. Note thatExtensionMethods
takes a constructor argumentcoll
of typeGenTraversableLike[A, Repr]
, whereA
represents the element type andRepr
represents (typically) the collection type. The implementation ofmapReduce
itself is straightforward.The interesting bit is the implicit conversion
withExtensions
, which returns an instance ofExtensionMethods
. This implicit conversion can only be applied if there is an implicit valuetraversable
of typeIsTraversableLike[Repr]
in scope. SinceIsTraversableLike
provides value memberconversion
, which gives us a way to convert between whatever type we wish to add an extension method to (in this case,Repr
) andGenTraversableLike[A, Repr]
, we can now convertcoll
from typeRepr
toGenTraversableLike[A, Repr]
. This allows us to create an instance of theExtensionMethods
class, which we pass our newGenTraversableLike[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 conversionwithExtensions
is generic, it will be applied as long as an implicit value of typeIsTraversableLike[Repr]
can be found. Given thatIsTraversableLike
contains implicit members that return values of typeIsTraversableLike
, this requirement is typically satisfied, and the chain of interactions described in the previous paragraph is set into action. (See theIsTraversableLike
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.
Implementing
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 ofIsTraversableLike
specific to the new type.Below is an example of an implementation of the
IsTraversableLike
trait where theRepr
type isString
.implicit val stringRepr: IsTraversableLike[String] { type A = Char } = new IsTraversableLike[String] { type A = Char val conversion = implicitly[String => GenTraversableLike[Char, String]] }
- Since
2.10
- type member
-
trait
IsTraversableOnce[Repr] extends AnyRef
Type class witnessing that a collection representation type
Repr
has elements of typeA
and has a conversion toGenTraversableOnce[A]
.Type class witnessing that a collection representation type
Repr
has elements of typeA
and has a conversion toGenTraversableOnce[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)
- Since
2.10
-
abstract
class
MapFactory[CC[A, B] <: Map[A, B] with MapLike[A, B, CC[A, B]]] extends GenMapFactory[CC]
A template for companion objects of
Map
and subclasses thereof. -
abstract
class
MutableMapFactory[CC[A, B] <: mutable.Map[A, B] with mutable.MapLike[A, B, CC[A, B]]] extends MapFactory[CC]
A template for companion objects of
mutable.Map
and subclasses thereof.A template for companion objects of
mutable.Map
and subclasses thereof.- Since
2.8
- abstract class MutableSetFactory[CC[X] <: mutable.Set[X] with mutable.SetLike[X, CC[X]]] extends SetFactory[CC]
-
abstract
class
MutableSortedMapFactory[CC[A, B] <: mutable.SortedMap[A, B] with SortedMapLike[A, B, CC[A, B]]] extends SortedMapFactory[CC]
A template for companion objects of
SortedMap
and subclasses thereof.A template for companion objects of
SortedMap
and subclasses thereof.- CC
the type of the collection.
- Version
2.12
- Since
2.12
- abstract class MutableSortedSetFactory[CC[A] <: mutable.SortedSet[A] with SortedSetLike[A, CC[A]] with mutable.Set[A] with mutable.SetLike[A, CC[A]]] extends SortedSetFactory[CC]
- abstract class OrderedTraversableFactory[CC[X] <: Traversable[X] with GenericOrderedTraversableTemplate[X, CC]] extends GenericOrderedCompanion[CC]
-
abstract
class
ParFactory[CC[X] <: ParIterable[X] with GenericParTemplate[X, CC]] extends GenTraversableFactory[CC] with GenericParCompanion[CC]
A template class for companion objects of
ParIterable
and subclasses thereof.A template class for companion objects of
ParIterable
and subclasses thereof. This class extendsTraversableFactory
and provides a set of operations to create
objects.ParIterable
-
abstract
class
ParMapFactory[CC[X, Y] <: ParMap[X, Y] with ParMapLike[X, Y, CC[X, Y], _]] extends GenMapFactory[CC] with GenericParMapCompanion[CC]
A template class for companion objects of
ParMap
and subclasses thereof.A template class for companion objects of
ParMap
and subclasses thereof. This class extendsTraversableFactory
and provides a set of operations to create
objects.ParMap
-
abstract
class
ParSetFactory[CC[X] <: ParSet[X] with ParSetLike[X, CC[X], _] with GenericParTemplate[X, CC]] extends GenSetFactory[CC] with GenericParCompanion[CC]
- Since
2.8
-
abstract
class
SeqFactory[CC[X] <: Seq[X] with GenericTraversableTemplate[X, CC]] extends GenSeqFactory[CC] with TraversableFactory[CC]
A template for companion objects of Seq and subclasses thereof.
A template for companion objects of Seq and subclasses thereof.
- Since
2.8
- abstract class SetFactory[CC[X] <: Set[X] with SetLike[X, CC[X]]] extends GenSetFactory[CC] with GenericSeqCompanion[CC]
-
trait
Shrinkable[-A] extends AnyRef
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.- Since
2.8
-
trait
Signalling extends AnyRef
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. -
trait
Sizing extends AnyRef
A trait for objects which have a size.
-
trait
Sorted[K, +This <: Sorted[K, This]] extends AnyRef
Any collection (including maps) whose keys (or elements) are ordered.
Any collection (including maps) whose keys (or elements) are ordered.
- Since
2.8
-
abstract
class
SortedMapFactory[CC[A, B] <: SortedMap[A, B] with SortedMapLike[A, B, CC[A, B]]] extends AnyRef
A template for companion objects of mutable.Map and subclasses thereof.
A template for companion objects of mutable.Map and subclasses thereof.
- Since
2.8
-
abstract
class
SortedSetFactory[CC[A] <: SortedSet[A] with SortedSetLike[A, CC[A]]] extends AnyRef
A template for companion objects of Set and subclasses thereof.
A template for companion objects of Set and subclasses thereof.
- Since
2.8
-
trait
Subtractable[A, +Repr <: Subtractable[A, Repr]] extends AnyRef
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-
.- A
the type of the elements of the collection.
- Repr
the type of the collection itself
- Since
2.8
-
class
TaggedDelegatedContext extends DelegatedContext
Class implementing delegated signalling, but having its own distinct
tag
. -
trait
TraversableFactory[CC[X] <: Traversable[X] with GenericTraversableTemplate[X, CC]] extends GenTraversableFactory[CC] with GenericSeqCompanion[CC]
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 createTraversable
objects. It is typically inherited by companion objects of subclasses ofTraversable
.- Since
2.8
-
trait
VolatileAbort extends Signalling
A mixin trait that implements abort flag behaviour using volatile variables.
-
type
ClassManifestTraversableFactory[CC[X] <: Traversable[X] with GenericClassManifestTraversableTemplate[X, CC]] = ClassTagTraversableFactory[CC]
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use ClassTagTraversableFactory instead
-
type
GenericClassManifestCompanion[+CC[X] <: Traversable[X]] = GenericClassTagCompanion[CC]
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use GenericClassTagCompanion instead
-
type
GenericClassManifestTraversableTemplate[+A, +CC[X] <: Traversable[X]] = GenericClassTagTraversableTemplate[A, CC]
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use GenericClassTagTraversableTemplate instead
-
trait
IterableForwarder[+A] extends Iterable[A] with TraversableForwarder[A]
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
- all calls creating a new iterable object of the same kind
The above methods are forwarded by subclass `IterableProxy`.
- Annotations
- @deprecated
- Deprecated
(Since version 2.11.0) forwarding is inherently unreliable since it is not automated and methods can be forgotten
- Since
2.8
-
trait
SeqForwarder[+A] extends Seq[A] with IterableForwarder[A]
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
- all calls creating a new sequence of the same kind
The above methods are forwarded by subclass
SeqProxy
.- Annotations
- @deprecated
- Deprecated
(Since version 2.11.0) forwarding is inherently unreliable since it is not automated and new methods can be forgotten
- Since
2.8
-
trait
TraversableForwarder[+A] extends Traversable[A]
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.
- Annotations
- @deprecated
- Deprecated
(Since version 2.11.0) forwarding is inherently unreliable since it is not automated and new methods can be forgotten
- Since
2.8
Value Members
-
object
IdleSignalling extends DefaultSignalling
An object that returns default values and ignores received signals.
- object IsSeqLike
- object IsTraversableLike
- object IsTraversableOnce
- object SliceInterval
This is the documentation for the Scala standard library.
Package structure
The scala package contains core types like
Int
,Float
,Array
orOption
which are accessible in all Scala compilation units without explicit qualification or imports.Notable packages include:
scala.collection
and its sub-packages contain Scala's collections frameworkscala.collection.immutable
- Immutable, sequential data-structures such asVector
,List
,Range
,HashMap
orHashSet
scala.collection.mutable
- Mutable, sequential data-structures such asArrayBuffer
,StringBuilder
,HashMap
orHashSet
scala.collection.concurrent
- Mutable, concurrent data-structures such asTrieMap
scala.collection.parallel.immutable
- Immutable, parallel data-structures such asParVector
,ParRange
,ParHashMap
orParHashSet
scala.collection.parallel.mutable
- Mutable, parallel data-structures such asParArray
,ParHashMap
,ParTrieMap
orParHashSet
scala.concurrent
- Primitives for concurrent programming such asFutures
andPromises
scala.io
- Input and output operationsscala.math
- Basic math functions and additional numeric types likeBigInt
andBigDecimal
scala.sys
- Interaction with other processes and the operating systemscala.util.matching
- Regular expressionsOther packages exist. See the complete list on the right.
Additional parts of the standard library are shipped as separate libraries. These include:
scala.reflect
- Scala's reflection API (scala-reflect.jar)scala.xml
- XML parsing, manipulation, and serialization (scala-xml.jar)scala.swing
- A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)scala.util.parsing
- Parser combinators (scala-parser-combinators.jar)Automatic imports
Identifiers in the scala package and the
scala.Predef
object are always in scope by default.Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example,
List
is an alias forscala.collection.immutable.List
.Other aliases refer to classes provided by the underlying platform. For example, on the JVM,
String
is an alias forjava.lang.String
.