### 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 `segmentLength``prefixLength``indexWhere``indexOf``lastIndexWhere``lastIndexOf``startsWith`,`endsWith``indexOfSlice`.

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 defiterator: Iterator[A]

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

3. #### abstract deflength: Int

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 >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Seq[A], B, That]): 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: (B, A) ⇒ 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: (A, B) ⇒ 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: StringBuilder, sep: String): StringBuilder

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

10. #### defaddString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder

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

11. #### defaggregate[B](z: B)(seqop: (B, A) ⇒ B, combop: (B, B) ⇒ B): B

Aggregates the results of applying an operator to subsequent elements.

12. #### defandThen[C](k: (A) ⇒ C): PartialFunction[Int, C]

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

13. #### defapplyOrElse[A1 <: Int, B1 >: A](x: A1, default: (A1) ⇒ B1): B1

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

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[A, B]): 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[A, B]): 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. #### defcompanion: GenericCompanion[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: Int, len: 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: (A, B) ⇒ 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. #### defdistinct: Seq[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: (A1, A1) ⇒ A1): A1

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

44. #### deffoldLeft[B](z: B)(op: (B, A) ⇒ 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: (A, B) ⇒ 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[B, Seq[B]]

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

49. #### defgroupBy[K](f: (A) ⇒ K): immutable.Map[K, Seq[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. #### defhasDefiniteSize: Boolean

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. #### defhead: A

Selects the first element of this sequence.

54. #### defheadOption: Option[A]

Optionally selects the first element.

56. #### defindexOf(elem: A, from: 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) ⇒ Boolean, from: 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. #### defindices: immutable.Range

Produces the range of all indices of this sequence.

63. #### definit: Seq[A]

Selects all elements except the last.

64. #### definits: Iterator[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. #### defisEmpty: Boolean

Tests whether this sequence is empty.

71. #### final defisTraversableAgain: Boolean

Tests whether this sequence can be repeatedly traversed.

72. #### deflast: A

Selects the last element.

73. #### deflastIndexOf(elem: A, end: 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) ⇒ Boolean, end: 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. #### deflastOption: Option[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. #### defmax: A

[use case] Finds the largest element.

85. #### defmin: A

[use case] Finds the smallest element.

87. #### defmkString: String

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: String, sep: String, end: String): String

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

90. #### defnonEmpty: Boolean

Tests whether the sequence is not empty.

91. #### deforElse[A1 <: Int, B1 >: A](that: PartialFunction[A1, B1]): PartialFunction[A1, B1]

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

92. #### defpadTo(len: Int, elem: A): Seq[A]

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

93. #### defpar: ParSeq[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: Int, that: 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. #### defpermutations: Iterator[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. #### defproduct: A

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

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

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

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

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

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

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

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

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

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

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

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

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

105. #### defrepr: Seq[A]

The collection of type sequence underlying this `TraversableLike` object.

106. #### defreverse: Seq[A]

Returns new sequence wih elements in reversed order.

107. #### defreverseIterator: Iterator[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 >: A, That](z: B)(op: (B, B) ⇒ B)(implicit cbf: CanBuildFrom[Seq[A], B, That]): That

Computes a prefix scan of the elements of the collection.

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

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

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

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

114. #### defsegmentLength(p: (A) ⇒ Boolean, from: Int): Int

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

115. #### defseq: Seq[A]

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

116. #### defsize: Int

The size of this sequence, equivalent to `length`.

117. #### defslice(from: Int, until: Int): Seq[A]

Selects an interval of elements.

118. #### defsliding(size: Int, step: 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: (A, A) ⇒ 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. #### defstringPrefix: String

Defines the prefix of this object's `toString` representation.

128. #### defsum: A

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

129. #### deftail: Seq[A]

Selects all elements except the first.

130. #### deftails: Iterator[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. #### deftoArray: Array[A]

[use case] Converts this sequence to an array.

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

Converts this sequence to a mutable buffer.

137. #### deftoIndexedSeq: immutable.IndexedSeq[A]

Converts this sequence to an indexed sequence.

138. #### deftoIterable: Iterable[A]

Converts this sequence to an iterable collection.

139. #### deftoIterator: Iterator[A]

Returns an Iterator over the elements in this sequence.

140. #### deftoList: List[A]

Converts this sequence to a list.

141. #### deftoMap[T, U]: Map[T, U]

[use case] Converts this sequence to a map.

143. #### deftoSeq: Seq[A]

Converts this sequence to a sequence.

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

Converts this sequence to a set.

145. #### deftoStream: immutable.Stream[A]

Converts this sequence to a stream.

146. #### deftoString(): String

Converts this sequence to a string.

147. #### deftoTraversable: Traversable[A]

Converts this sequence to an unspecified Traversable.

148. #### deftoVector: Vector[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[A1, A2](implicit asPair: (A) ⇒ (A1, A2)): (Seq[A1], Seq[A2])

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

152. #### defunzip3[A1, A2, A3](implicit asTriple: (A) ⇒ (A1, A2, A3)): (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: Int, elem: A): Seq[A]

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

154. #### defview(from: Int, until: Int): SeqView[A, Seq[A]]

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

155. #### defview: SeqView[A, Seq[A]]

Creates a non-strict view of this sequence.

156. #### defwithFilter(p: (A) ⇒ Boolean): FilterMonadic[A, Seq[A]]

Creates a non-strict filter of this sequence.

157. #### defzip[B](that: GenIterable[B]): Seq[(A, B)]

[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: A, thatElem: B): Seq[(A, B)]

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

159. #### defzipWithIndex: Seq[(A, Int)]

[use case] Zips this sequence with its indices.

### Deprecated Value Members

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

A syntactic sugar for out of order folding.