Builder

trait Builder[-A, +To] extends Growable[A]

Base trait for collection builders.

Base trait for collection builders.

After calling result() the behavior of a Builder (which is not also a scala.collection.mutable.ReusableBuilder) is undefined. No further methods should be called. It is common for mutable collections to be their own non-reusable Builder, in which case result() simply returns this.

See also

scala.collection.mutable.ReusableBuilder for Builders which can be reused after calling result()

trait Growable[A]
trait Clearable
class Object
trait Matchable
class Any
class Builder[K, V]
trait MapOps[K, V, CC, C]
class TrieMap[K, V]
class AnyRefMap[K, V]
class HashMap[K, V]
class LinkedHashMap[K, V]
class ListMap[K, V]
class LongMap[V]
trait Map[K, V]
trait Map[K, V]
class AbstractMap[K, V]
class WithDefault[K, V]
class WithDefault[K, V]
class TreeMap[K, V]
trait MultiMap[K, V]
trait SeqMap[K, V]
trait SortedMap[K, V]
trait SortedMapOps[K, V, CC, C]
class ofRef[T]
class ofByte
class ofShort
class ofChar
class ofInt
class ofLong
class ofFloat
class ofDouble
class ofBoolean
class ofUnit
class ListBuffer[A]
trait SetOps[A, CC, C]
class HashSet[A]
trait Set[A]
class AbstractSet[A]
class BitSet
class TreeSet[A]
trait SortedSet[A]
trait SortedSetOps[A, CC, C]
class Accumulator[A, CC, C]

Value members

Abstract methods

def clear(): Unit

Clears the contents of this builder.

Clears the contents of this builder. After execution of this method the builder will contain no elements.

def result(): To

Result collection consisting of all elements appended so far.

Result collection consisting of all elements appended so far.

Concrete methods

def mapResult[NewTo](f: To => NewTo): Builder[A, NewTo]

A builder resulting from this builder my mapping the result using f.

A builder resulting from this builder my mapping the result using f.

def sizeHint(size: Int): Unit

Gives a hint how many elements are expected to be added when the next result is called.

Gives a hint how many elements are expected to be added when the next result is called. Some builder classes will optimize their representation based on the hint. However, builder implementations are still required to work correctly even if the hint is wrong, i.e. a different number of elements is added.

Value Params
size

the hint how many elements will be added.

final def sizeHint(coll: IterableOnce[_], delta: Int): Unit

Gives a hint that one expects the result of this builder to have the same size as the given collection, plus some delta.

Gives a hint that one expects the result of this builder to have the same size as the given collection, plus some delta. This will provide a hint only if the collection has a known size Some builder classes will optimize their representation based on the hint. However, builder implementations are still required to work correctly even if the hint is wrong, i.e. a different number of elements is added.

Value Params
coll

the collection which serves as a hint for the result's size.

delta

a correction to add to the coll.size to produce the size hint.

final def sizeHintBounded(size: Int, boundingColl: Iterable[_]): Unit

Gives a hint how many elements are expected to be added when the next result is called, together with an upper bound given by the size of some other collection.

Gives a hint how many elements are expected to be added when the next result is called, together with an upper bound given by the size of some other collection. Some builder classes will optimize their representation based on the hint. However, builder implementations are still required to work correctly even if the hint is wrong, i.e. a different number of elements is added.

Value Params
boundingColl

the bounding collection. If it is an IndexedSeqLike, then sizes larger than collection's size are reduced.

size

the hint how many elements will be added.

Inherited methods

final def ++=(xs: IterableOnce[A]): Builder[A, To]

Alias for addAll

Alias for addAll

Inherited from
Growable
final def +=(elem: A): Builder[A, To]

Alias for addOne

Alias for addOne

Inherited from
Growable

Adds all elements produced by an IterableOnce to this growable collection.

Adds all elements produced by an IterableOnce to this growable collection.

Value Params
xs

the IterableOnce producing the elements to add.

Returns

the growable collection itself.

Inherited from
Growable
def addOne(elem: A): Builder[A, To]

Adds a single element to this growable collection.

Adds a single element to this growable collection.

Value Params
elem

the element to add.

Returns

the growable collection itself

Inherited from
Growable
Returns

The number of elements in the collection under construction, if it can be cheaply computed, -1 otherwise. The default implementation always returns -1.

Inherited from
Growable

Deprecated and Inherited methods

@deprecated("Use `++=` aka `addAll` instead of varargs `+=`; infix operations with an operand of multiple args will be deprecated", "2.13.0") @inline
final def +=(elem1: A, elem2: A, elems: A*): Builder[A, To]

Adds two or more elements to this growable collection.

Adds two or more elements to this growable collection.

Value Params
elem1

the first element to add.

elem2

the second element to add.

elems

the remaining elements to add.

Returns

the growable collection itself

Deprecated
Inherited from
Growable