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
The type of the collection elements.
- CC
The type constructor representing the collection class.
- Source
- GenericTraversableTemplate.scala
- Since
2.8
- Alphabetic
- By Inheritance
- GenericTraversableTemplate
- HasNewBuilder
- AnyRef
- Any
- by CollectionsHaveToParArray
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
companion: GenericCompanion[CC]
The factory companion object that builds instances of class Traversable.
The factory companion object that builds instances of class Traversable. (or its
Iterable
superclass where class Traversable is not aSeq
.) -
abstract
def
head: A
Selects the first element of this collection.
Selects the first element of this collection.
- returns
the first element of this collection.
- Exceptions thrown
NoSuchElementException
if the collection is empty.
-
abstract
def
isEmpty: Boolean
Tests whether this collection is empty.
Tests whether this collection is empty.
- returns
true
if the collection contain no elements,false
otherwise.
Concrete Value Members
-
def
flatten[B]: Traversable[B]
[use case] Converts this collection of traversable collections into a collection formed by the elements of these traversable collections.
[use case]Converts this collection of traversable collections into a collection formed by the elements of these traversable collections.
The resulting collection's type will be guided by the static type of collection. For example:
val xs = List( Set(1, 2, 3), Set(1, 2, 3) ).flatten // xs == List(1, 2, 3, 1, 2, 3) val ys = Set( List(1, 2, 3), List(3, 2, 1) ).flatten // ys == Set(1, 2, 3)
- B
the type of the elements of each traversable collection.
- returns
a new collection resulting from concatenating all element collections.
Full Signaturedef flatten[B](implicit asTraversable: (A) ⇒ GenTraversableOnce[B]): CC[B]
-
abstract
def
foreach(f: (A) ⇒ Unit): Unit
[use case]
[use case]- f
the function that is applied for its side-effect to every element. The result of function
f
is discarded.
Full Signatureabstract def foreach[U](f: (A) ⇒ U): Unit
-
def
genericBuilder[B]: Builder[B, CC[B]]
The generic builder that builds instances of Traversable at arbitrary element types.
-
def
toParArray: ParArray[T]
- Implicit
- This member is added by an implicit conversion from GenericTraversableTemplate[A, CC] to CollectionsHaveToParArray[GenericTraversableTemplate[A, CC], T] performed by method CollectionsHaveToParArray in scala.collection.parallel. This conversion will take place only if an implicit value of type (GenericTraversableTemplate[A, CC]) ⇒ GenTraversableOnce[T] is in scope.
- Definition Classes
- CollectionsHaveToParArray
-
def
transpose[B](implicit asTraversable: (A) ⇒ GenTraversableOnce[B]): CC[CC[B]]
Transposes this collection of traversable collections into a collection of collections.
Transposes this collection of traversable collections into a collection of collections.
The resulting collection's type will be guided by the static type of collection. For example:
val xs = List( Set(1, 2, 3), Set(4, 5, 6)).transpose // xs == List( // List(1, 4), // List(2, 5), // List(3, 6)) val ys = Vector( List(1, 2, 3), List(4, 5, 6)).transpose // ys == Vector( // Vector(1, 4), // Vector(2, 5), // Vector(3, 6))
- B
the type of the elements of each traversable collection.
- asTraversable
an implicit conversion which asserts that the element type of this collection is a
Traversable
.- returns
a two-dimensional collection of collections which has as nth row the nth column of this collection.
- Annotations
- @migration
- Migration
(Changed in version 2.9.0)
transpose
throws anIllegalArgumentException
if collections are not uniformly sized.- Exceptions thrown
IllegalArgumentException
if all collections in this collection are not of the same size.
-
def
unzip[A1, A2](implicit asPair: (A) ⇒ (A1, A2)): (CC[A1], CC[A2])
Converts this collection of pairs into two collections of the first and second half of each pair.
Converts this collection of pairs into two collections of the first and second half of each pair.
val xs = Traversable( (1, "one"), (2, "two"), (3, "three")).unzip // xs == (Traversable(1, 2, 3), // Traversable(one, two, three))
- A1
the type of the first half of the element pairs
- A2
the type of the second half of the element pairs
- asPair
an implicit conversion which asserts that the element type of this collection is a pair.
- returns
a pair of collections, containing the first, respectively second half of each element pair of this collection.
-
def
unzip3[A1, A2, A3](implicit asTriple: (A) ⇒ (A1, A2, A3)): (CC[A1], CC[A2], CC[A3])
Converts this collection of triples into three collections of the first, second, and third element of each triple.
Converts this collection of triples into three collections of the first, second, and third element of each triple.
val xs = Traversable( (1, "one", '1'), (2, "two", '2'), (3, "three", '3')).unzip3 // xs == (Traversable(1, 2, 3), // Traversable(one, two, three), // Traversable(1, 2, 3))
- A1
the type of the first member of the element triples
- A2
the type of the second member of the element triples
- A3
the type of the third member of the element triples
- asTriple
an implicit conversion which asserts that the element type of this collection is a triple.
- returns
a triple of collections, containing the first, second, respectively third member of each element triple of this collection.
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, including an example implementation of a JSON parser (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
.