Also note that the collections library was carefully designed to include several implementations of
each of the three basic collection types. These implementations have specific performance
characteristics which are described
in the guide.

Equivalent to x.hashCode except for boxed numeric types and null.
For numerics, it returns a hash value which is consistent
with value equality: if two value type instances compare
as true, then ## will produce the same hash value for each
of them.
For null returns a hashcode where null.hashCode throws a
NullPointerException.

[use case] Returns a new sequence containing the elements from the left hand operand followed by the elements from the
right hand operand.

[use case]

Returns a new sequence containing the elements from the left hand operand followed by the elements from the
right hand operand. The element type of the sequence is the most specific superclass encompassing
the element types of the two operands.

This overload exists because: for the implementation of ++: we should
reuse that of ++ because many collections override it with more
efficient versions.

Since TraversableOnce has no ++ method, we have to implement that
directly, but Traversable and down can use the overload.

B

the element type of the returned collection.

That

the class of the returned collection. Where possible, That is
the same class as the current collection class Repr, but this
depends on the element type B being admissible for that class,
which means that an implicit instance of type CanBuildFrom[Repr, B, That]
is found.

that

the traversable to append.

bf

an implicit value of class CanBuildFrom which determines
the result class That from the current representation type Repr and
and the new element type B.

returns

a new collection of type That which contains all elements
of this traversable collection followed by all elements of that.

Appends all elements of this collection to a string builder.
The written text consists of the string representations (w.r.t. the method
toString) of all elements of this collection without any separator string.

Appends all elements of this collection to a string builder using a separator string.

Appends all elements of this collection to a string builder using a separator string.
The written text consists of the string representations (w.r.t. the method toString)
of all elements of this collection, separated by the string sep.

Appends all elements of this collection to a string builder using start, end, and separator strings.

Appends all elements of this collection to a string builder using start, end, and separator strings.
The written text begins with the string start and ends with the string end.
Inside, the string representations (w.r.t. the method toString)
of all elements of this collection are separated by the string sep.

Aggregates the results of applying an operator to subsequent elements.

Aggregates the results of applying an operator to subsequent elements.

This is a more general form of fold and reduce. It is similar to
foldLeft in that it doesn't require the result to be a supertype of the
element type. In addition, it allows parallel collections to be processed
in chunks, and then combines the intermediate results.

aggregate splits the traversable or iterator into partitions and processes each
partition by sequentially applying seqop, starting with z (like
foldLeft). Those intermediate results are then combined by using
combop (like fold). The implementation of this operation may operate
on an arbitrary number of collection partitions (even 1), so combop may
be invoked an arbitrary number of times (even 0).

As an example, consider summing up the integer values of a list of chars.
The initial value for the sum is 0. First, seqop transforms each input
character to an Int and adds it to the sum (of the partition). Then,
combop just needs to sum up the intermediate results of the partitions:

the initial value for the accumulated result of the partition - this
will typically be the neutral element for the seqop operator (e.g.
Nil for list concatenation or 0 for summation) and may be evaluated
more than once

seqop

an operator used to accumulate results within a partition

combop

an associative operator used to combine results from different partitions

Applies this partial function to the given argument when it is contained in the function domain.

Applies this partial function to the given argument when it is contained in the function domain.
Applies fallback function where this partial function is not defined.

Note that expression pf.applyOrElse(x, default) is equivalent to

if(pf isDefinedAt x) pf(x) else default(x)

except that applyOrElse method can be implemented more efficiently.
For all partial function literals the compiler generates an applyOrElse implementation which
avoids double evaluation of pattern matchers and guards.
This makes applyOrElse the basis for the efficient implementation for many operations and scenarios, such as:

combining partial functions into orElse/andThen chains does not lead to
excessive apply/isDefinedAt evaluation

lift and unlift do not evaluate source functions twice on each invocation

For non-literal partial function classes with nontrivial isDefinedAt method
it is recommended to override applyOrElse with custom implementation that avoids
double isDefinedAt evaluation. This may result in better performance
and more predictable behavior w.r.t. side effects.

Note that the success of a cast at runtime is modulo Scala's erasure semantics.
Therefore the expression 1.asInstanceOf[String] will throw a ClassCastException at
runtime, while the expression List(1).asInstanceOf[List[String]] will not.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the requested type.

Iterates over combinations. A _combination_ of length n is a subsequence of
the original sequence, with the elements taken in order. Thus, "xy" and "yy"
are both length-2 combinations of "xyy", but "yx" is not. If there is
more than one way to generate the same subsequence, only one will be returned.

For example, "xyyy" has three different ways to generate "xy" depending on
whether the first, second, or third "y" is selected. However, since all are
identical, only one will be chosen. Which of the three will be taken is an
implementation detail that is not defined.

returns

An Iterator which traverses the possible n-element combinations of this sequence.

Copies the elements of this sequence to an array.
Fills the given array xs with values of this sequence.
Copying will stop once either the end of the current sequence is reached,
or the end of the target array is reached.

Copies the elements of this sequence to an array.
Fills the given array xs with values of this sequence, beginning at index start.
Copying will stop once either the end of the current sequence is reached,
or the end of the target array is reached.

Copies the elements of this sequence to an array.
Fills the given array xs with at most len elements of
this sequence, starting at position start.
Copying will stop once either the end of the current sequence is reached,
or the end of the target array is reached, or len elements have been copied.

[use case] Computes the multiset difference between this sequence and another sequence.

[use case]

Computes the multiset difference between this sequence and another sequence.

Note: will not terminate for infinite-sized collections.

that

the sequence of elements to remove

returns

a new sequence which contains all elements of this sequence
except some of occurrences of elements that also appear in that.
If an element value x appears
n times in that, then the first n occurrences of x will not form
part of the result, but any following occurrences will.

Tests whether the argument (that) is a reference to the receiver object (this).

Tests whether the argument (that) is a reference to the receiver object (this).

The eq method implements an equivalence relation on
non-null instances of AnyRef, and has three additional properties:

It is consistent: for any non-null instances x and y of type AnyRef, multiple invocations of
x.eq(y) consistently returns true or consistently returns false.

For any non-null instance x of type AnyRef, x.eq(null) and null.eq(x) returns false.

null.eq(null) returns true.

When overriding the equals or hashCode methods, it is important to ensure that their behavior is
consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2), they
should be equal to each other (o1 == o2) and they should hash to the same value (o1.hashCode == o2.hashCode).

returns

true if the argument is a reference to the receiver object; false otherwise.

Folds the elements of this traversable or iterator using the specified associative
binary operator.

Folds the elements of this traversable or iterator using the specified associative
binary operator.

The order in which operations are performed on elements is unspecified
and may be nondeterministic.

Note: will not terminate for infinite-sized collections.

A1

a type parameter for the binary operator, a supertype of A.

z

a neutral element for the fold operation; may be added to the result
an arbitrary number of times, and must not change the result (e.g., Nil for list concatenation,
0 for addition, or 1 for multiplication).

op

a binary operator that must be associative.

returns

the result of applying the fold operator op between all the elements and z, or z if this traversable or iterator is empty.

Tests whether this collection is known to have a finite size.
All strict collections are known to have finite size. For a non-strict
collection such as Stream, the predicate returns true if all
elements have been computed. It returns false if the stream is
not yet evaluated to the end. Non-empty Iterators usually return
false even if they were created from a collection with a known
finite size.

Note: many collection methods will not work on collections of infinite sizes.
The typical failure mode is an infinite loop. These methods always attempt a
traversal without checking first that hasDefiniteSize returns true.
However, checking hasDefiniteSize can provide an assurance that size is
well-defined and non-termination is not a concern.

returns

true if this collection is known to have finite size,
false otherwise.

Iterates over the inits of this traversable collection. The first value will be this
traversable collection and the final one will be an empty traversable collection, with the intervening
values the results of successive applications of init.

[use case] Computes the multiset intersection between this sequence and another sequence.

[use case]

Computes the multiset intersection between this sequence and another sequence.

Note: may not terminate for infinite-sized collections.

that

the sequence of elements to intersect with.

returns

a new sequence which contains all elements of this sequence
which also appear in that.
If an element value x appears
n times in that, then the first n occurrences of x will be retained
in the result, but any following occurrences will be omitted.

Note that the result of the test is modulo Scala's erasure semantics.
Therefore the expression 1.isInstanceOf[String] will return false, while the
expression List(1).isInstanceOf[List[String]] will return true.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the specified type.

returns

true if the receiver object is an instance of erasure of type T0; false otherwise.

a string representation of this collection. In the resulting string
the string representations (w.r.t. the method toString)
of all elements of this collection follow each other without any
separator string.

Displays all elements of this collection in a string using start, end, and
separator strings.

Displays all elements of this collection in a string using start, end, and
separator strings.

start

the starting string.

sep

the separator string.

end

the ending string.

returns

a string representation of this collection. The resulting string
begins with the string start and ends with the string
end. Inside, the string representations (w.r.t. the method
toString) of all elements of this collection are separated by
the string sep.

Composes this partial function with a fallback partial function which
gets applied where this partial function is not defined.

Composes this partial function with a fallback partial function which
gets applied where this partial function is not defined.

A1

the argument type of the fallback function

B1

the result type of the fallback function

that

the fallback function

returns

a partial function which has as domain the union of the domains
of this partial function and that. The resulting partial function
takes x to this(x) where this is defined, and to that(x) where it is not.

For most collection types, this method creates a new parallel collection by copying
all the elements. For these collection, par takes linear time. Mutable collections
in this category do not produce a mutable parallel collection that has the same
underlying dataset, so changes in one collection will not be reflected in the other one.

Specific collections (e.g. ParArray or mutable.ParHashMap) override this default
behaviour by creating a parallel collection which shares the same underlying dataset.
For these collections, par takes constant or sublinear time.

Partitions this traversable collection in two traversable collections according to a predicate.

Partitions this traversable collection in two traversable collections according to a predicate.

p

the predicate on which to partition.

returns

a pair of traversable collections: the first traversable collection consists of all elements that
satisfy the predicate p and the second traversable collection consists of all elements
that don't. The relative order of the elements in the resulting traversable collections
is the same as in the original traversable collection.

the product of all elements in this sequence of numbers of type Int.
Instead of Int, any other type T with an implicit Numeric[T] implementation
can be used as element type of the sequence and as result type of product.
Examples of such types are: Long, Float, Double, BigInt.

the sum of all elements in this sequence of numbers of type Int.
Instead of Int, any other type T with an implicit Numeric[T] implementation
can be used as element type of the sequence and as result type of sum.
Examples of such types are: Long, Float, Double, BigInt.

Iterates over the tails of this traversable collection. The first value will be this
traversable collection and the final one will be an empty traversable collection, with the intervening
values the results of successive applications of tail.

Converts this collection to an iterable collection. Note that
the choice of target Iterable is lazy in this default implementation
as this TraversableOnce may be lazy and unevaluated (i.e. it may
be an iterator which is only traversable once).

Converts this sequence to a map. This method is unavailable unless
the elements are members of Tuple2, each ((T, U)) becoming a key-value
pair in the map. Duplicate keys will be overwritten by later keys:
if this is an unordered collection, which key is in the resulting map
is undefined.

Note: will not terminate for infinite-sized collections.

returns

a map of type immutable.Map[T, U]
containing all key/value pairs of type (T, U) of this sequence.

Note: the difference between c filter p and c withFilter p is that
the former creates a new collection, whereas the latter only
restricts the domain of subsequent map, flatMap, foreach,
and withFilter operations.

Note: might return different results for different runs, unless the
underlying collection type is ordered.

p

the predicate used to test elements.

returns

an object of class WithFilter, which supports
map, flatMap, foreach, and withFilter operations.
All these operations apply to those elements of this traversable collection
which satisfy the predicate p.

[use case] Returns a sequence formed from this sequence and another iterable collection
by combining corresponding elements in pairs.

[use case]

Returns a sequence formed from this sequence and another iterable collection
by combining corresponding elements in pairs.
If one of the two collections is longer than the other, its remaining elements are ignored.

B

the type of the second half of the returned pairs

that

The iterable providing the second half of each result pair

returns

a new sequence containing pairs consisting of
corresponding elements of this sequence and that. The length
of the returned collection is the minimum of the lengths of this sequence and that.

[use case] Returns a sequence formed from this sequence and another iterable collection
by combining corresponding elements in pairs.

[use case]

Returns a sequence formed from this sequence and another iterable collection
by combining corresponding elements in pairs.
If one of the two collections is shorter than the other,
placeholder elements are used to extend the shorter collection to the length of the longer.

B

the type of the second half of the returned pairs

that

The iterable providing the second half of each result pair

thisElem

the element to be used to fill up the result if this sequence is shorter than that.

thatElem

the element to be used to fill up the result if that is shorter than this sequence.

returns

a new sequence containing pairs consisting of
corresponding elements of this sequence and that. The length
of the returned collection is the maximum of the lengths of this sequence and that.
If this sequence is shorter than that, thisElem values are used to pad the result.
If that is shorter than this sequence, thatElem values are used to pad the result.