Collections


A base trait for sequences.

Sequences are special cases of iterable collections of class Iterable. Unlike iterables, sequences always have a defined order of elements. Sequences provide a method apply for indexing. Indices range from 0 up to the length of a sequence. Sequences support a number of methods to find occurrences of elements or subsequences, including segmentLengthprefixLengthindexWhereindexOflastIndexWherelastIndexOfstartsWith,endsWithindexOfSlice.

Another way to see a sequence is as a PartialFunction from Int values to the element type of the sequence. The isDefinedAt method of a sequence returns true for the interval from 0 until length.

Sequences can be accessed in reverse order of their elements, using methods reverse and reverseIterator.

Sequences have two principal subtraits, IndexedSeq and LinearSeq, which give different guarantees for performance. An IndexedSeq provides fast random-access of elements and a fast length operation. A LinearSeq provides fast access only to the first element via head, but also has a fast tail operation.



Abstract Value Members

  1. abstract defapply(idx: Int)A

    Selects an element by its index in the sequence.

  2. abstract defiteratorIterator[A]

    Creates a new iterator over all elements contained in this iterable object.

  3. abstract deflengthInt

    The length of the sequence.

Concrete Value Members

  1. def++[B](that: GenTraversableOnce[B])Seq[B]

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

  2. def++:[B >: AThat](that: Traversable[B])(implicit bf: CanBuildFrom[Seq[A], BThat])That

    As with ++, returns a new collection containing the elements from the left operand followed by the elements from the right operand.

  3. def++:[B](that: TraversableOnce[B])Seq[B]

    [use case] As with ++, returns a new collection containing the elements from the left operand followed by the elements from the right operand.

  4. def+:(elem: A)Seq[A]

    [use case] A copy of the sequence with an element prepended.

  5. def/:[B](z: B)(op: (BA) ⇒ B)B

    Applies a binary operator to a start value and all elements of this sequence, going left to right.

  6. def:+(elem: A)Seq[A]

    [use case] A copy of this sequence with an element appended.

  7. def:\[B](z: B)(op: (AB) ⇒ B)B

    Applies a binary operator to all elements of this sequence and a start value, going right to left.

  8. defaddString(b: StringBuilder)StringBuilder

    Appends all elements of this sequence to a string builder.

  9. defaddString(b: StringBuildersep: String)StringBuilder

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

  10. defaddString(b: StringBuilderstart: Stringsep: Stringend: String)StringBuilder

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

  11. defaggregate[B](z: B)(seqop: (BA) ⇒ Bcombop: (BB) ⇒ B)B

    Aggregates the results of applying an operator to subsequent elements.

  12. defandThen[C](k: (A) ⇒ C)PartialFunction[IntC]

    Composes this partial function with a transformation function that gets applied to results of this partial function.

  13. defapplyOrElse[A1 <: IntB1 >: A](x: A1default: (A1) ⇒ B1)B1

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

  14. defasParIterableParIterable[A]

  15. defasParSeqParSeq[A]

  16. defcanEqual(that: Any)Boolean

    Method called from equality methods, so that user-defined subclasses can refuse to be equal to other collections of the same kind.

  17. defcollect[B](pf: PartialFunction[AB])Seq[B]

    [use case] Builds a new collection by applying a partial function to all elements of this sequence on which the function is defined.

  18. defcollectFirst[B](pf: PartialFunction[AB])Option[B]

    Finds the first element of the sequence for which the given partial function is defined, and applies the partial function to it.

  19. defcombinations(n: Int)Iterator[Seq[A]]

    Iterates over combinations.

  20. defcompanionGenericCompanion[Seq]

    The factory companion object that builds instances of class Seq.

  21. defcompose[A](g: (A) ⇒ Int): (A) ⇒ A

    Composes two instances of Function1 in a new Function1, with this function applied last.

  22. defcontains(elem: Any)Boolean

    Tests whether this sequence contains a given value as an element.

  23. defcontainsSlice[B](that: GenSeq[B])Boolean

    Tests whether this sequence contains a given sequence as a slice.

  24. defcopyToArray(xs: Array[A]start: Intlen: Int)Unit

    [use case] Copies elements of this sequence to an array.

  25. defcopyToArray(xs: Array[A])Unit

    [use case] Copies values of this sequence to an array.

  26. defcopyToArray(xs: Array[A]start: Int)Unit

    [use case] Copies values of this sequence to an array.

  27. defcopyToBuffer[B >: A](dest: Buffer[B])Unit

    Copies all elements of this sequence to a buffer.

  28. defcorresponds[B](that: GenSeq[B])(p: (AB) ⇒ Boolean)Boolean

    Tests whether every element of this sequence relates to the corresponding element of another sequence by satisfying a test predicate.

  29. defcount(p: (A) ⇒ Boolean)Int

    Counts the number of elements in the sequence which satisfy a predicate.

  30. defdiff(that: Seq[A])Seq[A]

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

  31. defdistinctSeq[A]

    Builds a new sequence from this sequence without any duplicate elements.

  32. defdrop(n: Int)Seq[A]

    Selects all elements except first n ones.

  33. defdropRight(n: Int)Seq[A]

    Selects all elements except last n ones.

  34. defdropWhile(p: (A) ⇒ Boolean)Seq[A]

    Drops longest prefix of elements that satisfy a predicate.

  35. defendsWith[B](that: GenSeq[B])Boolean

    Tests whether this sequence ends with the given sequence.

  36. defequals(that: Any)Boolean

    The equals method for arbitrary sequences.

  37. defexists(p: (A) ⇒ Boolean)Boolean

    Tests whether a predicate holds for some of the elements of this sequence.

  38. deffilter(p: (A) ⇒ Boolean)Seq[A]

    Selects all elements of this sequence which satisfy a predicate.

  39. deffilterNot(p: (A) ⇒ Boolean)Seq[A]

    Selects all elements of this sequence which do not satisfy a predicate.

  40. deffind(p: (A) ⇒ Boolean)Option[A]

    Finds the first element of the sequence satisfying a predicate, if any.

  41. defflatMap[B](f: (A) ⇒ GenTraversableOnce[B])Seq[B]

    [use case] Builds a new collection by applying a function to all elements of this sequence and using the elements of the resulting collections.

  42. defflatten[B]Seq[B]

    [use case] Converts this sequence of traversable collections into a sequence formed by the elements of these traversable collections.

  43. deffold[A1 >: A](z: A1)(op: (A1A1) ⇒ A1)A1

    Folds the elements of this sequence using the specified associative binary operator.

  44. deffoldLeft[B](z: B)(op: (BA) ⇒ B)B

    Applies a binary operator to a start value and all elements of this sequence, going left to right.

  45. deffoldRight[B](z: B)(op: (AB) ⇒ B)B

    Applies a binary operator to all elements of this sequence and a start value, going right to left.

  46. defforall(p: (A) ⇒ Boolean)Boolean

    Tests whether a predicate holds for all elements of this sequence.

  47. defforeach(f: (A) ⇒ Unit)Unit

    [use case] Applies a function f to all elements of this sequence.

  48. defgenericBuilder[B]Builder[BSeq[B]]

    The generic builder that builds instances of Seq at arbitrary element types.

  49. defgroupBy[K](f: (A) ⇒ K)immutable.Map[KSeq[A]]

    Partitions this sequence into a map of sequences according to some discriminator function.

  50. defgrouped(size: Int)Iterator[Seq[A]]

    Partitions elements in fixed size sequences.

  51. defhasDefiniteSizeBoolean

    Tests whether this sequence is known to have a finite size.

  52. defhashCode()Int

    Hashcodes for Seq produce a value from the hashcodes of all the elements of the sequence.

  53. defheadA

    Selects the first element of this sequence.

  54. defheadOptionOption[A]

    Optionally selects the first element.

  55. defifParSeq[R](isbody: (ParSeq[A]) ⇒ R): (TraversableOps[A])#Otherwise[R]

  56. defindexOf(elem: Afrom: Int)Int

    [use case] Finds index of first occurrence of some value in this sequence after or at some start index.

  57. defindexOf(elem: A)Int

    [use case] Finds index of first occurrence of some value in this sequence.

  58. defindexOfSlice[B >: A](that: GenSeq[B]from: Int)Int

    Finds first index after or at a start index where this sequence contains a given sequence as a slice.

  59. defindexOfSlice[B >: A](that: GenSeq[B])Int

    Finds first index where this sequence contains a given sequence as a slice.

  60. defindexWhere(p: (A) ⇒ Booleanfrom: Int)Int

    Finds index of the first element satisfying some predicate after or at some start index.

  61. defindexWhere(p: (A) ⇒ Boolean)Int

    Finds index of first element satisfying some predicate.

  62. defindicesimmutable.Range

    Produces the range of all indices of this sequence.

  63. definitSeq[A]

    Selects all elements except the last.

  64. definitsIterator[Seq[A]]

    Iterates over the inits of this sequence.

  65. defintersect(that: Seq[A])Seq[A]

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

  66. defisDefinedAt(idx: Int)Boolean

    Tests whether this sequence contains given index.

  67. defisEmptyBoolean

    Tests whether this sequence is empty.

  68. defisParIterableBoolean

  69. defisParSeqBoolean

  70. defisParallelBoolean

  71. final defisTraversableAgainBoolean

    Tests whether this sequence can be repeatedly traversed.

  72. deflastA

    Selects the last element.

  73. deflastIndexOf(elem: Aend: Int)Int

    [use case] Finds index of last occurrence of some value in this sequence before or at a given end index.

  74. deflastIndexOf(elem: A)Int

    [use case] Finds index of last occurrence of some value in this sequence.

  75. deflastIndexOfSlice[B >: A](that: GenSeq[B]end: Int)Int

    Finds last index before or at a given end index where this sequence contains a given sequence as a slice.

  76. deflastIndexOfSlice[B >: A](that: GenSeq[B])Int

    Finds last index where this sequence contains a given sequence as a slice.

  77. deflastIndexWhere(p: (A) ⇒ Booleanend: Int)Int

    Finds index of last element satisfying some predicate before or at given end index.

  78. deflastIndexWhere(p: (A) ⇒ Boolean)Int

    Finds index of last element satisfying some predicate.

  79. deflastOptionOption[A]

    Optionally selects the last element.

  80. deflengthCompare(len: Int)Int

    Compares the length of this sequence to a test value.

  81. deflift: (Int) ⇒ Option[A]

    Turns this partial function into an plain function returning an Option result.

  82. defmap[B](f: (A) ⇒ B)Seq[B]

    [use case] Builds a new collection by applying a function to all elements of this sequence.

  83. defmaxA

    [use case] Finds the largest element.

  84. defmaxBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B])A

  85. defminA

    [use case] Finds the smallest element.

  86. defminBy[B](f: (A) ⇒ B)(implicit cmp: Ordering[B])A

  87. defmkStringString

    Displays all elements of this sequence in a string.

  88. defmkString(sep: String)String

    Displays all elements of this sequence in a string using a separator string.

  89. defmkString(start: Stringsep: Stringend: String)String

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

  90. defnonEmptyBoolean

    Tests whether the sequence is not empty.

  91. deforElse[A1 <: IntB1 >: A](that: PartialFunction[A1B1])PartialFunction[A1B1]

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

  92. defpadTo(len: Intelem: A)Seq[A]

    [use case] A copy of this sequence with an element value appended until a given target length is reached.

  93. defparParSeq[A]

    Returns a parallel implementation of this collection.

  94. defpartition(p: (A) ⇒ Boolean): (Seq[A], Seq[A])

    Partitions this sequence in two sequences according to a predicate.

  95. defpatch(from: Intthat: GenSeq[A]replaced: Int)Seq[A]

    [use case] Produces a new sequence where a slice of elements in this sequence is replaced by another sequence.

  96. defpermutationsIterator[Seq[A]]

    Iterates over distinct permutations.

  97. defprefixLength(p: (A) ⇒ Boolean)Int

    Returns the length of the longest prefix whose elements all satisfy some predicate.

  98. defproductA

    [use case] Multiplies up the elements of this collection.

  99. defreduce[A1 >: A](op: (A1A1) ⇒ A1)A1

    Reduces the elements of this sequence using the specified associative binary operator.

  100. defreduceLeft[B >: A](op: (BA) ⇒ B)B

    Applies a binary operator to all elements of this sequence, going left to right.

  101. defreduceLeftOption[B >: A](op: (BA) ⇒ B)Option[B]

    Optionally applies a binary operator to all elements of this sequence, going left to right.

  102. defreduceOption[A1 >: A](op: (A1A1) ⇒ A1)Option[A1]

    Reduces the elements of this sequence, if any, using the specified associative binary operator.

  103. defreduceRight[B >: A](op: (AB) ⇒ B)B

    Applies a binary operator to all elements of this sequence, going right to left.

  104. defreduceRightOption[B >: A](op: (AB) ⇒ B)Option[B]

    Optionally applies a binary operator to all elements of this sequence, going right to left.

  105. defreprSeq[A]

    The collection of type sequence underlying this TraversableLike object.

  106. defreverseSeq[A]

    Returns new sequence wih elements in reversed order.

  107. defreverseIteratorIterator[A]

    An iterator yielding elements in reversed order.

  108. defreverseMap[B](f: (A) ⇒ B)Seq[B]

    [use case] Builds a new collection by applying a function to all elements of this sequence and collecting the results in reversed order.

  109. defrunWith[U](action: (A) ⇒ U): (Int) ⇒ Boolean

    Composes this partial function with an action function which gets applied to results of this partial function.

  110. defsameElements(that: GenIterable[A])Boolean

    [use case] Checks if the other iterable collection contains the same elements in the same order as this sequence.

  111. defscan[B >: AThat](z: B)(op: (BB) ⇒ B)(implicit cbf: CanBuildFrom[Seq[A], BThat])That

    Computes a prefix scan of the elements of the collection.

  112. defscanLeft[BThat](z: B)(op: (BA) ⇒ B)(implicit bf: CanBuildFrom[Seq[A], BThat])That

    Produces a collection containing cumulative results of applying the operator going left to right.

  113. defscanRight[BThat](z: B)(op: (AB) ⇒ B)(implicit bf: CanBuildFrom[Seq[A], BThat])That

    Produces a collection containing cumulative results of applying the operator going right to left.

  114. defsegmentLength(p: (A) ⇒ Booleanfrom: Int)Int

    Computes length of longest segment whose elements all satisfy some predicate.

  115. defseqSeq[A]

    A version of this collection with all of the operations implemented sequentially (i.

  116. defsizeInt

    The size of this sequence, equivalent to length.

  117. defslice(from: Intuntil: Int)Seq[A]

    Selects an interval of elements.

  118. defsliding(size: Intstep: Int)Iterator[Seq[A]]

    Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.

  119. defsliding(size: Int)Iterator[Seq[A]]

    Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped.

  120. defsortBy[B](f: (A) ⇒ B)(implicit ord: math.Ordering[B])Seq[A]

    Sorts this Seq according to the Ordering which results from transforming an implicitly given Ordering with a transformation function.

  121. defsortWith(lt: (AA) ⇒ Boolean)Seq[A]

    Sorts this sequence according to a comparison function.

  122. defsorted[B >: A](implicit ord: math.Ordering[B])Seq[A]

    Sorts this sequence according to an Ordering.

  123. defspan(p: (A) ⇒ Boolean): (Seq[A], Seq[A])

    Splits this sequence into a prefix/suffix pair according to a predicate.

  124. defsplitAt(n: Int): (Seq[A], Seq[A])

    Splits this sequence into two at a given position.

  125. defstartsWith[B](that: GenSeq[B]offset: Int)Boolean

    Tests whether this sequence contains the given sequence at a given index.

  126. defstartsWith[B](that: GenSeq[B])Boolean

    Tests whether this sequence starts with the given sequence.

  127. defstringPrefixString

    Defines the prefix of this object's toString representation.

  128. defsumA

    [use case] Sums up the elements of this collection.

  129. deftailSeq[A]

    Selects all elements except the first.

  130. deftailsIterator[Seq[A]]

    Iterates over the tails of this sequence.

  131. deftake(n: Int)Seq[A]

    Selects first n elements.

  132. deftakeRight(n: Int)Seq[A]

    Selects last n elements.

  133. deftakeWhile(p: (A) ⇒ Boolean)Seq[A]

    Takes longest prefix of elements that satisfy a predicate.

  134. defto[Col[_]]Col[A]

    [use case] Converts this sequence into another by copying all elements.

  135. deftoArrayArray[A]

    [use case] Converts this sequence to an array.

  136. deftoBuffer[B >: A]Buffer[B]

    Converts this sequence to a mutable buffer.

  137. deftoIndexedSeqimmutable.IndexedSeq[A]

    Converts this sequence to an indexed sequence.

  138. deftoIterableIterable[A]

    Converts this sequence to an iterable collection.

  139. deftoIteratorIterator[A]

    Returns an Iterator over the elements in this sequence.

  140. deftoListList[A]

    Converts this sequence to a list.

  141. deftoMap[TU]Map[TU]

    [use case] Converts this sequence to a map.

  142. deftoParArrayParArray[A]

  143. deftoSeqSeq[A]

    Converts this sequence to a sequence.

  144. deftoSet[B >: A]immutable.Set[B]

    Converts this sequence to a set.

  145. deftoStreamimmutable.Stream[A]

    Converts this sequence to a stream.

  146. deftoString()String

    Converts this sequence to a string.

  147. deftoTraversableTraversable[A]

    Converts this sequence to an unspecified Traversable.

  148. deftoVectorVector[A]

    Converts this sequence to a Vector.

  149. deftranspose[B](implicit asTraversable: (A) ⇒ GenTraversableOnce[B])Seq[Seq[B]]

    Transposes this sequence of traversable collections into a sequence of sequences.

  150. defunion(that: Seq[A])Seq[A]

    [use case] Produces a new sequence which contains all elements of this sequence and also all elements of a given sequence.

  151. defunzip[A1A2](implicit asPair: (A) ⇒ (A1A2)): (Seq[A1], Seq[A2])

    Converts this sequence of pairs into two collections of the first and second half of each pair.

  152. defunzip3[A1A2A3](implicit asTriple: (A) ⇒ (A1A2A3)): (Seq[A1], Seq[A2], Seq[A3])

    Converts this sequence of triples into three collections of the first, second, and third element of each triple.

  153. defupdated(index: Intelem: A)Seq[A]

    [use case] A copy of this sequence with one single replaced element.

  154. defview(from: Intuntil: Int)SeqView[ASeq[A]]

    Creates a non-strict view of a slice of this sequence.

  155. defviewSeqView[ASeq[A]]

    Creates a non-strict view of this sequence.

  156. defwithFilter(p: (A) ⇒ Boolean)FilterMonadic[ASeq[A]]

    Creates a non-strict filter of this sequence.

  157. defzip[B](that: GenIterable[B])Seq[(AB)]

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

  158. defzipAll[B](that: Iterable[B]thisElem: AthatElem: B)Seq[(AB)]

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

  159. defzipWithIndexSeq[(AInt)]

    [use case] Zips this sequence with its indices.

Shadowed Implict Value Members

  1. deffilter(p: (A) ⇒ Boolean)TraversableOnce[A]

  2. defflatMap[B](f: (A) ⇒ GenTraversableOnce[B])TraversableOnce[B]

  3. defmap[B](f: (A) ⇒ B)TraversableOnce[B]

  4. defwithFilter(p: (A) ⇒ Boolean)Iterator[A]

Deprecated Value Members

  1. def/:\[A1 >: A](z: A1)(op: (A1A1) ⇒ A1)A1

    A syntactic sugar for out of order folding.


















Comments