scala.collection.parallel.ParSeqLike#Elements

abstract class Elements extends SeqSplitter[T] with scala.BufferedIterator[T]

Used to iterate elements using indices

Type Members

class Appended[U >: T, PI <: SeqSplitter[U]] extends SeqSplitter.Appended[U, PI] with SeqSplitter[U]

  • Definition Classes
    • SeqSplitter

class GroupedIterator[B >: A] extends AbstractIterator[Seq[B]] with Iterator[Seq[B]]

A flexible iterator for transforming an Iterator[A] into an Iterator[Seq[A]], with configurable sequence size, step, and strategy for dealing with elements which don’t fit evenly.

Typical uses can be achieved via methods grouped and sliding .

  • Definition Classes
    • Iterator

class Mapped[S] extends SeqSplitter.Mapped[S] with SeqSplitter[S]

  • Definition Classes
    • SeqSplitter

class Patched[U >: T] extends SeqSplitter[U]

  • Definition Classes
    • SeqSplitter

class Taken extends SeqSplitter.Taken with SeqSplitter[T]

  • Definition Classes
    • SeqSplitter

class Zipped[S] extends SeqSplitter.Zipped[S] with SeqSplitter[(T, S)]

  • Definition Classes
    • SeqSplitter

class ZippedAll[U >: T, S] extends SeqSplitter.ZippedAll[U, S] with SeqSplitter[(U, S)]

  • Definition Classes
    • SeqSplitter

Value Members From scala.collection.BufferedIterator

def buffered: Elements.this.type

Creates a buffered iterator from this iterator.

  • returns
    • a buffered iterator producing the same values as this iterator.
  • Definition Classes
    • BufferedIterator → Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.
  • See also
    • scala.collection.BufferedIterator

(defined at scala.collection.BufferedIterator)

Value Members From scala.collection.Iterator

def ++[B >: T](that: ⇒ GenTraversableOnce[B]): Iterator[B]

[use case]

Concatenates this iterator with another.

  • that
    • the other iterator
  • returns
    • a new iterator that first yields the values produced by this iterator followed by the values produced by iterator that .
  • Definition Classes
    • Iterator

(defined at scala.collection.Iterator)

def collect[B](pf: PartialFunction[T, B]): Iterator[B]

Creates an iterator by transforming values produced by this iterator with a partial function, dropping those values for which the partial function is not defined.

  • pf
    • the partial function which filters and maps the iterator.
  • returns
    • a new iterator which yields each value x produced by this iterator for which pf is defined the image pf(x) .
  • Definition Classes
    • Iterator
  • Annotations
    • @migration
  • Migration
    • (Changed in version 2.8.0) collect has changed. The previous behavior can be reproduced with toSeq .
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def contains(elem: Any): Boolean

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

Note: may not terminate for infinite iterators.

  • elem
    • the element to test.
  • returns
    • true if this iterator produces some value that is is equal (as determined by == ) to elem , false otherwise.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

(defined at scala.collection.Iterator)

def corresponds[B](that: GenTraversableOnce[B])(p: (T, B) ⇒ Boolean): Boolean

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

  • B
    • the type of the elements of that
  • that
    • the other collection
  • p
    • the test predicate, which relates elements from both collections
  • returns
    • true if both collections have the same length and p(x, y) is true for all corresponding elements x of this iterator and y of that , otherwise false
  • Definition Classes
    • Iterator

(defined at scala.collection.Iterator)

def dropWhile(p: (T) ⇒ Boolean): Iterator[T]

Skips longest sequence of elements of this iterator which satisfy given predicate p , and returns an iterator of the remaining elements.

  • p
    • the predicate used to skip elements.
  • returns
    • an iterator consisting of the remaining elements
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def duplicate: (Iterator[T], Iterator[T])

Creates two new iterators that both iterate over the same elements as this iterator (in the same order). The duplicate iterators are considered equal if they are positioned at the same element.

Given that most methods on iterators will make the original iterator unfit for further use, this methods provides a reliable way of calling multiple such methods on an iterator.

  • returns
    • a pair of iterators
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterators that were returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterators as well., The implementation may allocate temporary storage for elements iterated by one iterator but not yet by the other.

(defined at scala.collection.Iterator)

def exists(p: (T) ⇒ Boolean): Boolean

Tests whether a predicate holds for some of the values produced by this iterator.

Note: may not terminate for infinite iterators.

  • p
    • the predicate used to test elements.
  • returns
    • true if the given predicate p holds for some of the values produced by this iterator, otherwise false .
  • Definition Classes
    • Iterator → TraversableOnce → GenTraversableOnce
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

(defined at scala.collection.Iterator)

def filter(p: (T) ⇒ Boolean): Iterator[T]

Returns an iterator over all the elements of this iterator that satisfy the predicate p . The order of the elements is preserved.

  • p
    • the predicate used to test values.
  • returns
    • an iterator which produces those values of this iterator which satisfy the predicate p .
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def filterNot(p: (T) ⇒ Boolean): Iterator[T]

Creates an iterator over all the elements of this iterator which do not satisfy a predicate p.

  • p
    • the predicate used to test values.
  • returns
    • an iterator which produces those values of this iterator which do not satisfy the predicate p .
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def find(p: (T) ⇒ Boolean): Option[T]

Finds the first value produced by the iterator satisfying a predicate, if any.

Note: may not terminate for infinite iterators.

  • p
    • the predicate used to test values.
  • returns
    • an option value containing the first value produced by the iterator that satisfies predicate p , or None if none exists.
  • Definition Classes
    • Iterator → TraversableOnce → GenTraversableOnce
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

(defined at scala.collection.Iterator)

def flatMap[B](f: (T) ⇒ GenTraversableOnce[B]): Iterator[B]

Creates a new iterator by applying a function to all values produced by this iterator and concatenating the results.

  • f
    • the function to apply on each element.
  • returns
    • the iterator resulting from applying the given iterator-valued function f to each value produced by this iterator and concatenating the results.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def forall(p: (T) ⇒ Boolean): Boolean

Tests whether a predicate holds for all values produced by this iterator.

Note: may not terminate for infinite iterators.

  • p
    • the predicate used to test elements.
  • returns
    • true if the given predicate p holds for all values produced by this iterator, otherwise false .
  • Definition Classes
    • Iterator → TraversableOnce → GenTraversableOnce
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

(defined at scala.collection.Iterator)

def foreach[U](f: (T) ⇒ U): Unit

[use case]

Applies a function f to all values produced by this iterator.

  • f
    • the function that is applied for its side-effect to every element. The result of function f is discarded.
  • Definition Classes
    • Iterator → TraversableOnce → GenTraversableOnce

(defined at scala.collection.Iterator)

def grouped[B >: T](size: Int): GroupedIterator[B]

Returns an iterator which groups this iterator into fixed size blocks. Example usages:

// Returns List(List(1, 2, 3), List(4, 5, 6), List(7)))
(1 to 7).iterator grouped 3 toList
// Returns List(List(1, 2, 3), List(4, 5, 6))
(1 to 7).iterator grouped 3 withPartial false toList
// Returns List(List(1, 2, 3), List(4, 5, 6), List(7, 20, 25)
// Illustrating that withPadding's argument is by-name.
val it2 = Iterator.iterate(20)(_ + 5)
(1 to 7).iterator grouped 3 withPadding it2.next toList
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def indexOf[B >: T](elem: B): Int

Returns the index of the first occurrence of the specified object in this iterable object.

Note: may not terminate for infinite iterators.

  • elem
    • element to search for.
  • returns
    • the index of the first occurrence of elem in the values produced by this iterator, or -1 if such an element does not exist until the end of the iterator is reached.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

(defined at scala.collection.Iterator)

def indexOf[B >: T](elem: B, from: Int): Int

Returns the index of the first occurrence of the specified object in this iterable object after or at some start index.

Note: may not terminate for infinite iterators.

  • elem
    • element to search for.
  • from
    • the start index
  • returns
    • the index >= from of the first occurrence of elem in the values produced by this iterator, or -1 if such an element does not exist until the end of the iterator is reached.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

(defined at scala.collection.Iterator)

def indexWhere(p: (T) ⇒ Boolean, from: Int): Int

Returns the index of the first produced value satisfying a predicate, or -1, after or at some start index.

Note: may not terminate for infinite iterators.

  • p
    • the predicate to test values
  • from
    • the start index
  • returns
    • the index >= from of the first produced value satisfying p , or -1 if such an element does not exist until the end of the iterator is reached.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

(defined at scala.collection.Iterator)

def padTo[A1 >: T](len: Int, elem: A1): Iterator[A1]

[use case]

Appends an element value to this iterator until a given target length is reached.

  • len
    • the target length
  • elem
    • the padding value
  • returns
    • a new iterator consisting of producing all values of this iterator, followed by the minimal number of occurrences of elem so that the number of produced values is at least len .
  • Definition Classes
    • Iterator

(defined at scala.collection.Iterator)

def partition(p: (T) ⇒ Boolean): (Iterator[T], Iterator[T])

Partitions this iterator in two iterators according to a predicate.

  • p
    • the predicate on which to partition
  • returns
    • a pair of iterators: the iterator that satisfies the predicate p and the iterator that does not. The relative order of the elements in the resulting iterators is the same as in the original iterator.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterators that were returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterators as well.

(defined at scala.collection.Iterator)

def patch[B >: T](from: Int, patchElems: Iterator[B], replaced: Int): Iterator[B]

Returns this iterator with patched values. Patching at negative indices is the same as patching starting at 0. Patching at indices at or larger than the length of the original iterator appends the patch to the end. If more values are replaced than actually exist, the excess is ignored.

  • from
    • The start index from which to patch
  • patchElems
    • The iterator of patch values
  • replaced
    • The number of values in the original iterator that are replaced by the patch.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, as well as the one passed as a parameter, and use only the iterator that was returned. Using the old iterators is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def sameElements(that: Iterator[_]): Boolean

Tests if another iterator produces the same values as this one.

Note: will not terminate for infinite iterators.

  • that
    • the other iterator
  • returns
    • true , if both iterators produce the same elements in the same order, false otherwise.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, as well as the one passed as parameter. Using the old iterators is undefined and subject to change.

(defined at scala.collection.Iterator)

def scanLeft[B](z: B)(op: (B, T) ⇒ B): Iterator[B]

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

Note: will not terminate for infinite iterators.

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

  • B
    • the type of the elements in the resulting collection
  • z
    • the initial value
  • op
    • the binary operator applied to the intermediate result and the element
  • returns
    • iterator with intermediate results
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def scanRight[B](z: B)(op: (T, B) ⇒ B): Iterator[B]

Produces a collection containing cumulative results of applying the operator going right to left. The head of the collection is the last cumulative result.

Note: will not terminate for infinite iterators.

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

  • B
    • the type of the elements in the resulting collection
  • z
    • the initial value
  • op
    • the binary operator applied to the intermediate result and the element
  • returns
    • iterator with intermediate results
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

Example:

Iterator(1, 2, 3, 4).scanRight(0)(_ + _).toList == List(10, 9, 7, 4, 0)

(defined at scala.collection.Iterator)

def seq: Iterator[T]

A version of this collection with all of the operations implemented sequentially (i.e., in a single-threaded manner).

This method returns a reference to this collection. In parallel collections, it is redefined to return a sequential implementation of this collection. In both cases, it has O(1) complexity.

  • returns
    • a sequential view of the collection.
  • Definition Classes
    • Iterator → TraversableOnce → GenTraversableOnce

(defined at scala.collection.Iterator)

def sliceIterator(from: Int, until: Int): Iterator[T]

Creates an optionally bounded slice, unbounded if until is negative.

  • Attributes
    • protected
  • Definition Classes
    • Iterator

(defined at scala.collection.Iterator)

def sliding[B >: T](size: Int, step: Int = 1): GroupedIterator[B]

Returns an iterator which presents a “sliding window” view of another iterator. The first argument is the window size, and the second is how far to advance the window on each iteration; defaults to 1 . Example usages:

// Returns List(List(1, 2, 3), List(2, 3, 4), List(3, 4, 5))
(1 to 5).iterator.sliding(3).toList
// Returns List(List(1, 2, 3, 4), List(4, 5))
(1 to 5).iterator.sliding(4, 3).toList
// Returns List(List(1, 2, 3, 4))
(1 to 5).iterator.sliding(4, 3).withPartial(false).toList
// Returns List(List(1, 2, 3, 4), List(4, 5, 20, 25))
// Illustrating that withPadding's argument is by-name.
val it2 = Iterator.iterate(20)(_ + 5)
(1 to 5).iterator.sliding(4, 3).withPadding(it2.next).toList
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def span(p: (T) ⇒ Boolean): (Iterator[T], Iterator[T])

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

  • p
    • the test predicate
  • returns
    • a pair of Iterators consisting of the longest prefix of this whose elements all satisfy p , and the rest of the Iterator.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterators that were returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterators as well.

(defined at scala.collection.Iterator)

def takeWhile(p: (T) ⇒ Boolean): Iterator[T]

Takes longest prefix of values produced by this iterator that satisfy a predicate.

  • p
    • The predicate used to test elements.
  • returns
    • An iterator returning the values produced by this iterator, until this iterator produces a value that does not satisfy the predicate p .
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def toIterator: Iterator[T]

Returns an Iterator over the elements in this traversable or iterator. Will return the same Iterator if this instance is already an Iterator.

Note: will not terminate for infinite iterators.

  • returns
    • an Iterator containing all elements of this traversable or iterator.
  • Definition Classes
    • Iterator → GenTraversableOnce

(defined at scala.collection.Iterator)

def toStream: immutable.Stream[T]

Converts this traversable or iterator to a stream.

  • returns
    • a stream containing all elements of this traversable or iterator.
  • Definition Classes
    • Iterator → GenTraversableOnce

(defined at scala.collection.Iterator)

def toTraversable: Traversable[T]

Converts this traversable or iterator to an unspecified Traversable. Will return the same collection if this instance is already Traversable.

Note: will not terminate for infinite iterators.

  • returns
    • a Traversable containing all elements of this traversable or iterator.
  • Definition Classes
    • Iterator → TraversableOnce → GenTraversableOnce

(defined at scala.collection.Iterator)

def withFilter(p: (T) ⇒ Boolean): Iterator[T]

Creates an iterator over all the elements of this iterator that satisfy the predicate p . The order of the elements is preserved.

Note: withFilter is the same as filter on iterators. It exists so that for-expressions with filters work over iterators.

  • p
    • the predicate used to test values.
  • returns
    • an iterator which produces those values of this iterator which satisfy the predicate p .
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def zipAll[B, A1 >: T, B1 >: B](that: Iterator[B], thisElem: A1, thatElem: B1): Iterator[(A1, B1)]

[use case]

Creates an iterator formed from this iterator and another iterator by combining corresponding elements in pairs. If one of the two iterators is shorter than the other, placeholder elements are used to extend the shorter iterator to the length of the longer.

  • that
    • iterator that may have a different length as the self iterator.
  • thisElem
    • element thisElem is used to fill up the resulting iterator if the self iterator is shorter than that
  • thatElem
    • element thatElem is used to fill up the resulting iterator if that is shorter than the self iterator
  • returns
    • a new iterator containing pairs consisting of corresponding values of this iterator and that . The length of the returned iterator is the maximum of the lengths of this iterator and that . If this iterator is shorter than that , thisElem values are used to pad the result. If that is shorter than this iterator, thatElem values are used to pad the result.
  • Definition Classes
    • Iterator

(defined at scala.collection.Iterator)

def zipWithIndex: Iterator[(T, Int)]

Creates an iterator that pairs each element produced by this iterator with its index, counting from 0.

  • returns
    • a new iterator containing pairs consisting of corresponding elements of this iterator and their indices.
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

def zip[B](that: Iterator[B]): Iterator[(T, B)]

Creates an iterator formed from this iterator and another iterator by combining corresponding values in pairs. If one of the two iterators is longer than the other, its remaining elements are ignored.

  • that
    • The iterator providing the second half of each result pair
  • returns
    • a new iterator containing pairs consisting of corresponding elements of this iterator and that . The number of elements returned by the new iterator is the minimum of the number of elements returned by this iterator and that .
  • Definition Classes
    • Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, as well as the one passed as a parameter, and use only the iterator that was returned. Using the old iterators is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.Iterator)

Value Members From scala.collection.TraversableOnce

def /:[B](z: B)(op: (B, T) ⇒ B): B

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

Note: /: is alternate syntax for foldLeft ; z /: xs is the same as xs foldLeft z .

Examples:

Note that the folding function used to compute b is equivalent to that used to compute c.

scala> val a = List(1,2,3,4)
a: List[Int] = List(1, 2, 3, 4)

scala> val b = (5 /: a)(_+_)
b: Int = 15

scala> val c = (5 /: a)((x,y) => x + y)
c: Int = 15

Note: will not terminate for infinite-sized collections.

Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.

  • B
    • the result type of the binary operator.
  • z
    • the start value.
  • op
    • the binary operator.
  • returns
    • the result of inserting op between consecutive elements of this traversable or iterator, going left to right with the start value z on the left:
    op(...op(op(z, x_1), x_2), ..., x_n)
    
where `x1, ..., xn` are the elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def :\[B](z: B)(op: (T, B) ⇒ B): B

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

Note: :\ is alternate syntax for foldRight ; xs :\ z is the same as xs foldRight z .

Note: will not terminate for infinite-sized collections.

Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.

Examples:

Note that the folding function used to compute b is equivalent to that used to compute c.

scala> val a = List(1,2,3,4)
a: List[Int] = List(1, 2, 3, 4)

scala> val b = (a :\ 5)(_+_)
b: Int = 15

scala> val c = (a :\ 5)((x,y) => x + y)
c: Int = 15
  • B
    • the result type of the binary operator.
  • z
    • the start value
  • op
    • the binary operator
  • returns
    • the result of inserting op between consecutive elements of this traversable or iterator, going right to left with the start value z on the right:
    op(x_1, op(x_2, ... op(x_n, z)...))
    
where `x1, ..., xn` are the elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def addString(b: StringBuilder): StringBuilder

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

Example:

scala> val a = List(1,2,3,4)
a: List[Int] = List(1, 2, 3, 4)

scala> val b = new StringBuilder()
b: StringBuilder =

scala> val h = a.addString(b)
h: StringBuilder = 1234
  • b
    • the string builder to which elements are appended.
  • returns
    • the string builder b to which elements were appended.
  • Definition Classes
    • TraversableOnce

(defined at scala.collection.TraversableOnce)

def addString(b: StringBuilder, sep: String): StringBuilder

Appends all elements of this traversable or iterator 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 traversable or iterator, separated by the string sep .

Example:

scala> val a = List(1,2,3,4)
a: List[Int] = List(1, 2, 3, 4)

scala> val b = new StringBuilder()
b: StringBuilder =

scala> a.addString(b, ", ")
res0: StringBuilder = 1, 2, 3, 4
  • b
    • the string builder to which elements are appended.
  • sep
    • the separator string.
  • returns
    • the string builder b to which elements were appended.
  • Definition Classes
    • TraversableOnce

(defined at scala.collection.TraversableOnce)

def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder

Appends all elements of this traversable or iterator 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 traversable or iterator are separated by the string sep .

Example:

scala> val a = List(1,2,3,4)
a: List[Int] = List(1, 2, 3, 4)

scala> val b = new StringBuilder()
b: StringBuilder =

scala> a.addString(b , "List(" , ", " , ")")
res5: StringBuilder = List(1, 2, 3, 4)
  • b
    • the string builder to which elements are appended.
  • start
    • the starting string.
  • sep
    • the separator string.
  • end
    • the ending string.
  • returns
    • the string builder b to which elements were appended.
  • Definition Classes
    • TraversableOnce

(defined at scala.collection.TraversableOnce)

def aggregate[B](z: ⇒ B)(seqop: (B, T) ⇒ B, combop: (B, B) ⇒ B): B

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:

List('a', 'b', 'c').aggregate(0)({ (sum, ch) => sum + ch.toInt }, { (p1, p2) => p1 + p2 })
  • B
    • the type of accumulated results
  • z
    • 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
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def collectFirst[B](pf: PartialFunction[T, B]): Option[B]

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

Note: may not terminate for infinite-sized collections.

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

  • pf
    • the partial function
  • returns
    • an option value containing pf applied to the first value for which it is defined, or None if none exists.
  • Definition Classes
    • TraversableOnce

Example:

Seq("a", 1, 5L).collectFirst({ case x: Int => x*10 }) = Some(10)

(defined at scala.collection.TraversableOnce)

def copyToArray[B >: T](xs: Array[B]): Unit

[use case]

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

Note: will not terminate for infinite iterators.

  • xs
    • the array to fill.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def copyToArray[B >: T](xs: Array[B], start: Int): Unit

[use case]

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

Note: will not terminate for infinite iterators.

  • xs
    • the array to fill.
  • start
    • the starting index.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def copyToBuffer[B >: T](dest: Buffer[B]): Unit

Copies all elements of this traversable or iterator to a buffer.

Note: will not terminate for infinite-sized collections.

  • dest
    • The buffer to which elements are copied.
  • Definition Classes
    • TraversableOnce

(defined at scala.collection.TraversableOnce)

def foldLeft[B](z: B)(op: (B, T) ⇒ B): B

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

Note: will not terminate for infinite-sized collections.

Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.

  • B
    • the result type of the binary operator.
  • z
    • the start value.
  • op
    • the binary operator.
  • returns
    • the result of inserting op between consecutive elements of this traversable or iterator, going left to right with the start value z on the left:
    op(...op(z, x_1), x_2, ..., x_n)
    
where `x1, ..., xn` are the elements of this traversable or iterator.
Returns `z` if this traversable or iterator is empty.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def foldRight[B](z: B)(op: (T, B) ⇒ B): B

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

Note: will not terminate for infinite-sized collections.

Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.

  • B
    • the result type of the binary operator.
  • z
    • the start value.
  • op
    • the binary operator.
  • returns
    • the result of inserting op between consecutive elements of this traversable or iterator, going right to left with the start value z on the right:
    op(x_1, op(x_2, ... op(x_n, z)...))
    
where `x1, ..., xn` are the elements of this traversable or iterator.
Returns `z` if this traversable or iterator is empty.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def maxBy[B](f: (T) ⇒ B)(implicit cmp: Ordering[B]): T

[use case]

Finds the first element which yields the largest value measured by function f.

  • B
    • The result type of the function f.
  • f
    • The measuring function.
  • returns
    • the first element of this traversable or iterator with the largest value measured by function f.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def minBy[B](f: (T) ⇒ B)(implicit cmp: Ordering[B]): T

[use case]

Finds the first element which yields the smallest value measured by function f.

  • B
    • The result type of the function f.
  • f
    • The measuring function.
  • returns
    • the first element of this traversable or iterator with the smallest value measured by function f.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def mkString(sep: String): String

Displays all elements of this traversable or iterator in a string using a separator string.

  • sep
    • the separator string.
  • returns
    • a string representation of this traversable or iterator. In the resulting string the string representations (w.r.t. the method toString ) of all elements of this traversable or iterator are separated by the string sep .
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

Example:

List(1, 2, 3).mkString("|") = "1|2|3"

(defined at scala.collection.TraversableOnce)

def mkString(start: String, sep: String, end: String): String

Displays all elements of this traversable or iterator 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 traversable or iterator. 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 traversable or iterator are separated by the string sep .
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

Example:

List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"

(defined at scala.collection.TraversableOnce)

def reduceLeftOption[B >: T](op: (B, T) ⇒ B): Option[B]

Optionally applies a binary operator to all elements of this traversable or iterator, going left to right.

Note: will not terminate for infinite-sized collections.

Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.

  • B
    • the result type of the binary operator.
  • op
    • the binary operator.
  • returns
    • an option value containing the result of reduceLeft(op) if this traversable or iterator is nonempty, None otherwise.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def reduceLeft[B >: T](op: (B, T) ⇒ B): B

Applies a binary operator to all elements of this traversable or iterator, going left to right.

Note: will not terminate for infinite-sized collections.

Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.

  • B
    • the result type of the binary operator.
  • op
    • the binary operator.
  • returns
    • the result of inserting op between consecutive elements of this traversable or iterator, going left to right:
    op( op( ... op(x_1, x_2) ..., x_{n-1}), x_n)
    
where `x1, ..., xn` are the elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce
  • Exceptions thrown
    • UnsupportedOperationException if this traversable or iterator is empty.

(defined at scala.collection.TraversableOnce)

def reduceOption[A1 >: T](op: (A1, A1) ⇒ A1): Option[A1]

Reduces the elements of this traversable or iterator, if any, using the specified associative binary operator.

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

  • A1
    • A type parameter for the binary operator, a supertype of A .
  • op
    • A binary operator that must be associative.
  • returns
    • An option value containing result of applying reduce operator op between all the elements if the collection is nonempty, and None otherwise.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def reduceRightOption[B >: T](op: (T, B) ⇒ B): Option[B]

Optionally applies a binary operator to all elements of this traversable or iterator, going right to left.

Note: will not terminate for infinite-sized collections.

Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.

  • B
    • the result type of the binary operator.
  • op
    • the binary operator.
  • returns
    • an option value containing the result of reduceRight(op) if this traversable or iterator is nonempty, None otherwise.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def reduceRight[B >: T](op: (T, B) ⇒ B): B

Applies a binary operator to all elements of this traversable or iterator, going right to left.

Note: will not terminate for infinite-sized collections.

Note: might return different results for different runs, unless the underlying collection type is ordered or the operator is associative and commutative.

  • B
    • the result type of the binary operator.
  • op
    • the binary operator.
  • returns
    • the result of inserting op between consecutive elements of this traversable or iterator, going right to left:
    op(x_1, op(x_2, ..., op(x_{n-1}, x_n)...))
    
where `x1, ..., xn` are the elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce
  • Exceptions thrown
    • UnsupportedOperationException if this traversable or iterator is empty.

(defined at scala.collection.TraversableOnce)

def reversed: List[T]

  • Attributes
    • protected[this]
  • Definition Classes
    • TraversableOnce

(defined at scala.collection.TraversableOnce)

def toBuffer[B >: T]: Buffer[B]

Uses the contents of this traversable or iterator to create a new mutable buffer.

Note: will not terminate for infinite-sized collections.

  • returns
    • a buffer containing all elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def toIndexedSeq: immutable.IndexedSeq[T]

Converts this traversable or iterator to an indexed sequence.

Note: will not terminate for infinite-sized collections.

  • returns
    • an indexed sequence containing all elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def toIterable: Iterable[T]

Converts this traversable or iterator 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).

Note: will not terminate for infinite-sized collections.

  • returns
    • an Iterable containing all elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def toList: List[T]

Converts this traversable or iterator to a list.

Note: will not terminate for infinite-sized collections.

  • returns
    • a list containing all elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def toMap[T, U](implicit ev: <:<[T, (T, U)]): immutable.Map[T, U]

[use case]

Converts this traversable or iterator 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 iterators.

  • returns
    • a map of type immutable.Map[T, U] containing all key/value pairs of type (T, U) of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def toSeq: Seq[T]

Converts this traversable or iterator to a sequence. As with toIterable , it’s lazy in this default implementation, as this TraversableOnce may be lazy and unevaluated.

Note: will not terminate for infinite-sized collections.

  • returns
    • a sequence containing all elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def toSet[B >: T]: immutable.Set[B]

Converts this traversable or iterator to a set.

Note: will not terminate for infinite-sized collections.

  • returns
    • a set containing all elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

def toVector: Vector[T]

Converts this traversable or iterator to a Vector.

Note: will not terminate for infinite-sized collections.

  • returns
    • a vector containing all elements of this traversable or iterator.
  • Definition Classes
    • TraversableOnce → GenTraversableOnce

(defined at scala.collection.TraversableOnce)

Value Members From scala.collection.generic.DelegatedSignalling

def setIndexFlag(f: Int): Unit

Sets the value of the index flag.

The index flag holds an integer which carries some operation-specific meaning. For instance, takeWhile operation sets the index flag to the position of the element where the predicate fails. Other workers may check this index against the indices they are working on and return if this index is smaller than their index. Examples of operations using this are takeWhile , dropWhile , span and indexOf .

  • f
    • the value to which the index flag is set.
  • Definition Classes
    • DelegatedSignalling → Signalling

(defined at scala.collection.generic.DelegatedSignalling)

def setIndexFlagIfGreater(f: Int): Unit

Sets the value of the index flag if argument is greater than current value. This method does this atomically.

The index flag holds an integer which carries some operation-specific meaning. For instance, takeWhile operation sets the index flag to the position of the element where the predicate fails. Other workers may check this index against the indices they are working on and return if this index is smaller than their index. Examples of operations using this are takeWhile , dropWhile , span and indexOf .

  • f
    • the value to which the index flag is set
  • Definition Classes
    • DelegatedSignalling → Signalling

(defined at scala.collection.generic.DelegatedSignalling)

def setIndexFlagIfLesser(f: Int): Unit

Sets the value of the index flag if argument is lesser than current value. This method does this atomically.

The index flag holds an integer which carries some operation-specific meaning. For instance, takeWhile operation sets the index flag to the position of the element where the predicate fails. Other workers may check this index against the indices they are working on and return if this index is smaller than their index. Examples of operations using this are takeWhile , dropWhile , span and indexOf .

  • f
    • the value to which the index flag is set
  • Definition Classes
    • DelegatedSignalling → Signalling

(defined at scala.collection.generic.DelegatedSignalling)

Value Members From scala.collection.parallel.AugmentedIterableIterator

def collect2combiner[S, That](pf: PartialFunction[T, S], cb: Combiner[S, That]): Combiner[S, That]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def copy2builder[U >: T, Coll, Bld <: Builder[U, Coll]](b: Bld): Bld

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def copyToArray[U >: T](array: Array[U], from: Int, len: Int): Unit

[use case]

Copies selected values produced by this iterator to an array. Fills the given array xs starting at index start with at most len values produced by this iterator. Copying will stop once either the end of the current iterator is reached, or the end of the array is reached, or len elements have been copied.

Note: will not terminate for infinite iterators.

  • xs
    • the array to fill.
  • start
    • the starting index.
  • len
    • the maximal number of elements to copy.
  • Definition Classes
    • AugmentedIterableIterator → Iterator → TraversableOnce → GenTraversableOnce

(defined at scala.collection.parallel.AugmentedIterableIterator)

def count(p: (T) ⇒ Boolean): Int

Counts the number of elements in the traversable or iterator which satisfy a predicate.

  • p
    • the predicate used to test elements.
  • returns
    • the number of elements satisfying the predicate p .
  • Definition Classes
    • AugmentedIterableIterator → TraversableOnce → GenTraversableOnce

(defined at scala.collection.parallel.AugmentedIterableIterator)

def drop2combiner[U >: T, This](n: Int, cb: Combiner[U, This]): Combiner[U, This]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def filter2combiner[U >: T, This](pred: (T) ⇒ Boolean, cb: Combiner[U, This]): Combiner[U, This]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def filterNot2combiner[U >: T, This](pred: (T) ⇒ Boolean, cb: Combiner[U, This]): Combiner[U, This]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def flatmap2combiner[S, That](f: (T) ⇒ GenTraversableOnce[S], cb: Combiner[S, That]): Combiner[S, That]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def fold[U >: T](z: U)(op: (U, U) ⇒ U): U

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 iterators.

  • 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.
  • Definition Classes
    • AugmentedIterableIterator → TraversableOnce → GenTraversableOnce

(defined at scala.collection.parallel.AugmentedIterableIterator)

def map2combiner[S, That](f: (T) ⇒ S, cb: Combiner[S, That]): Combiner[S, That]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def partition2combiners[U >: T, This](pred: (T) ⇒ Boolean, btrue: Combiner[U, This], bfalse: Combiner[U, This]): (Combiner[U, This], Combiner[U, This])

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def reduceLeft[U >: T](howmany: Int, op: (U, U) ⇒ U): U

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def reduce[U >: T](op: (U, U) ⇒ U): U

Reduces 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.

  • op
    • A binary operator that must be associative.
  • returns
    • The result of applying reduce operator op between all the elements if the traversable or iterator is nonempty.
  • Definition Classes
    • AugmentedIterableIterator → TraversableOnce → GenTraversableOnce
  • Exceptions thrown
    • UnsupportedOperationException if this traversable or iterator is empty.

(defined at scala.collection.parallel.AugmentedIterableIterator)

def scanToArray[U >: T, A >: U](z: U, op: (U, U) ⇒ U, array: Array[A], from: Int): Unit

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def scanToCombiner[U >: T, That](howmany: Int, startValue: U, op: (U, U) ⇒ U, cb: Combiner[U, That]): Combiner[U, That]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def scanToCombiner[U >: T, That](startValue: U, op: (U, U) ⇒ U, cb: Combiner[U, That]): Combiner[U, That]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def slice2combiner[U >: T, This](from: Int, until: Int, cb: Combiner[U, This]): Combiner[U, This]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def span2combiners[U >: T, This](p: (T) ⇒ Boolean, before: Combiner[U, This], after: Combiner[U, This]): (Combiner[U, This], Combiner[U, This])

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def splitAt2combiners[U >: T, This](at: Int, before: Combiner[U, This], after: Combiner[U, This]): (Combiner[U, This], Combiner[U, This])

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def take2combiner[U >: T, This](n: Int, cb: Combiner[U, This]): Combiner[U, This]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def takeWhile2combiner[U >: T, This](p: (T) ⇒ Boolean, cb: Combiner[U, This]): (Combiner[U, This], Boolean)

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def zip2combiner[U >: T, S, That](otherpit: RemainsIterator[S], cb: Combiner[(U, S), That]): Combiner[(U, S), That]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

def zipAll2combiner[U >: T, S, That](that: RemainsIterator[S], thiselem: U, thatelem: S, cb: Combiner[(U, S), That]): Combiner[(U, S), That]

  • Definition Classes
    • AugmentedIterableIterator

(defined at scala.collection.parallel.AugmentedIterableIterator)

Value Members From scala.collection.parallel.AugmentedSeqIterator

def corresponds[S](corr: (T, S) ⇒ Boolean)(that: scala.Iterator[S]): Boolean

  • Definition Classes
    • AugmentedSeqIterator

(defined at scala.collection.parallel.AugmentedSeqIterator)

def indexWhere(pred: (T) ⇒ Boolean): Int

Returns the index of the first produced value satisfying a predicate, or -1.

Note: may not terminate for infinite iterators.

  • returns
    • the index of the first produced value satisfying p , or -1 if such an element does not exist until the end of the iterator is reached.
  • Definition Classes
    • AugmentedSeqIterator → Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.

(defined at scala.collection.parallel.AugmentedSeqIterator)

def lastIndexWhere(pred: (T) ⇒ Boolean): Int

  • Definition Classes
    • AugmentedSeqIterator

(defined at scala.collection.parallel.AugmentedSeqIterator)

def prefixLength(pred: (T) ⇒ Boolean): Int

  • Definition Classes
    • AugmentedSeqIterator

(defined at scala.collection.parallel.AugmentedSeqIterator)

def reverse2combiner[U >: T, This](cb: Combiner[U, This]): Combiner[U, This]

  • Definition Classes
    • AugmentedSeqIterator

(defined at scala.collection.parallel.AugmentedSeqIterator)

def reverseMap2combiner[S, That](f: (T) ⇒ S, cb: Combiner[S, That]): Combiner[S, That]

  • Definition Classes
    • AugmentedSeqIterator

(defined at scala.collection.parallel.AugmentedSeqIterator)

def updated2combiner[U >: T, That](index: Int, elem: U, cb: Combiner[U, That]): Combiner[U, That]

  • Definition Classes
    • AugmentedSeqIterator

(defined at scala.collection.parallel.AugmentedSeqIterator)

Value Members From scala.collection.parallel.IterableSplitter

def appendParIterable[U >: T, PI <: IterableSplitter[U]](that: PI): Elements.Appended[U, PI]

  • Definition Classes
    • IterableSplitter

(defined at scala.collection.parallel.IterableSplitter)

def buildString(closure: ((String) ⇒ Unit) ⇒ Unit): String

  • Attributes
    • protected
  • Definition Classes
    • IterableSplitter

(defined at scala.collection.parallel.IterableSplitter)

def drop(n: Int): IterableSplitter[T]

Drop implemented as simple eager consumption.

  • n
    • the number of elements to drop
  • returns
    • an iterator which produces all values of the current iterator, except it omits the first n values.
  • Definition Classes
    • IterableSplitter → Iterator

(defined at scala.collection.parallel.IterableSplitter)

def shouldSplitFurther[S](coll: ParIterable[S], parallelismLevel: Int): Boolean

  • Definition Classes
    • IterableSplitter

(defined at scala.collection.parallel.IterableSplitter)

var signalDelegate: Signalling

A delegate that method calls are redirected to.

  • Definition Classes
    • IterableSplitter → DelegatedSignalling

(defined at scala.collection.parallel.IterableSplitter)

Instance Constructors From scala.collection.parallel.ParSeqLike.Elements

new Elements(start: Int, end: Int)

(defined at scala.collection.parallel.ParSeqLike.Elements)

Value Members From scala.collection.parallel.ParSeqLike.Elements

def dup: Elements

Creates a copy of this iterator.

  • Definition Classes
    • Elements → SeqSplitter → IterableSplitter

(defined at scala.collection.parallel.ParSeqLike.Elements)

def psplit(sizes: Int*): scala.Seq[SeqSplitter[T]]

Splits the splitter into disjunct views.

This overloaded version of the split method is specific to precise splitters. It returns a sequence of splitters, each iterating some subset of the elements in this splitter. The sizes of the subsplitters in the partition is equal to the size in the corresponding argument, as long as there are enough elements in this splitter to split it that way.

If there aren’t enough elements, a zero element splitter is appended for each additional argument. If there are additional elements, an additional splitter is appended at the end to compensate.

For example, say we have a splitter ps with 100 elements. Invoking:

ps.split(50, 25, 25, 10, 5)

will return a sequence of five splitters, last two views being empty. On the other hand, calling:

ps.split(50, 40)

will return a sequence of three splitters, last of them containing ten elements.

Note: this method actually invalidates the current splitter.

Unlike the case with split found in splitters, views returned by this method can be empty.

  • sizes
    • the sizes used to split this split iterator into iterators that traverse disjunct subsets
  • returns
    • a sequence of disjunct subsequence iterators of this parallel iterator
  • Definition Classes
    • Elements → SeqSplitter → PreciseSplitter

(defined at scala.collection.parallel.ParSeqLike.Elements)

def split: Seq[SeqSplitter[T]]

Splits the iterator into a sequence of disjunct views.

Returns a sequence of split iterators, each iterating over some subset of the elements in the collection. These subsets are disjoint and should be approximately equal in size. These subsets are not empty, unless the iterator is empty in which case this method returns a sequence with a single empty iterator. If the splitter has more than two elements, this method will return two or more splitters.

Implementors are advised to keep this partition relatively small - two splitters are already enough when partitioning the collection, although there may be a few more.

Note: this method actually invalidates the current splitter.

  • returns
    • a sequence of disjunct iterators of the collection
  • Definition Classes
    • Elements → SeqSplitter → PreciseSplitter → IterableSplitter → Splitter

(defined at scala.collection.parallel.ParSeqLike.Elements)

Value Members From scala.collection.parallel.SeqSplitter

def appendParSeq[U >: T, PI <: SeqSplitter[U]](that: PI): Appended[U, PI]

  • Definition Classes
    • SeqSplitter

(defined at scala.collection.parallel.SeqSplitter)

def map[S](f: (T) ⇒ S): Mapped[S]

Creates a new iterator that maps all produced values of this iterator to new values using a transformation function.

  • f
    • the transformation function
  • returns
    • a new iterator which transforms every value produced by this iterator by applying the function f to it.
  • Definition Classes
    • SeqSplitter → IterableSplitter → Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.parallel.SeqSplitter)

def patchParSeq[U >: T](from: Int, patchElems: SeqSplitter[U], replaced: Int): Patched[U]

  • Definition Classes
    • SeqSplitter

(defined at scala.collection.parallel.SeqSplitter)

def psplitWithSignalling(sizes: Int*): scala.Seq[SeqSplitter[T]]

  • Definition Classes
    • SeqSplitter

(defined at scala.collection.parallel.SeqSplitter)

def reverse: SeqSplitter[T]

  • Definition Classes
    • SeqSplitter

(defined at scala.collection.parallel.SeqSplitter)

def slice(from1: Int, until1: Int): SeqSplitter[T]

Creates an iterator returning an interval of the values produced by this iterator.

  • returns
    • an iterator which advances this iterator past the first from elements using drop , and then takes until - from elements, using take .
  • Definition Classes
    • SeqSplitter → IterableSplitter → Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.parallel.SeqSplitter)

def splitWithSignalling: scala.Seq[SeqSplitter[T]]

  • Definition Classes
    • SeqSplitter → IterableSplitter

(defined at scala.collection.parallel.SeqSplitter)

def take(n: Int): SeqSplitter[T]

Selects first n values of this iterator.

  • n
    • the number of values to take
  • returns
    • an iterator producing only the first n values of this iterator, or else the whole iterator, if it produces fewer than n values.
  • Definition Classes
    • SeqSplitter → IterableSplitter → Iterator
  • Note
    • Reuse: After calling this method, one should discard the iterator it was called on, and use only the iterator that was returned. Using the old iterator is undefined, subject to change, and may result in changes to the new iterator as well.

(defined at scala.collection.parallel.SeqSplitter)

def zipAllParSeq[S, U >: T, R >: S](that: SeqSplitter[S], thisElem: U, thatElem: R): ZippedAll[U, R]

  • Definition Classes
    • SeqSplitter → IterableSplitter

(defined at scala.collection.parallel.SeqSplitter)

def zipParSeq[S](that: SeqSplitter[S]): Zipped[S]

  • Definition Classes
    • SeqSplitter → IterableSplitter

(defined at scala.collection.parallel.SeqSplitter)


Value Members From Implicit scala.collection.parallel.CollectionsHaveToParArray ——————————————————————————–

def toParArray: ParArray[T]

  • Implicit information
    • This member is added by an implicit conversion from Elements to CollectionsHaveToParArray [Elements, T] performed by method CollectionsHaveToParArray in scala.collection.parallel. This conversion will take place only if an implicit value of type (Elements) ⇒ GenTraversableOnce [T] is in scope.
  • Definition Classes
    • CollectionsHaveToParArray (added by implicit convertion: scala.collection.parallel.CollectionsHaveToParArray)

Full Source:

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2003-2013, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

package scala
package collection.parallel

import scala.collection.{ SeqLike, GenSeq, GenIterable, Iterator }
import scala.collection.generic.DefaultSignalling
import scala.collection.generic.AtomicIndexFlag
import scala.collection.generic.CanBuildFrom
import scala.collection.generic.VolatileAbort

import scala.collection.parallel.ParallelCollectionImplicits._

/** A template trait for sequences of type `ParSeq[T]`, representing
 *  parallel sequences with element type `T`.
 *
 *  $parallelseqinfo
 *
 *  @tparam T           the type of the elements contained in this collection
 *  @tparam Repr        the type of the actual collection containing the elements
 *  @tparam Sequential  the type of the sequential version of this parallel collection
 *
 *  @define parallelseqinfo
 *  Parallel sequences inherit the `Seq` trait. Their indexing and length computations
 *  are defined to be efficient. Like their sequential counterparts
 *  they always have a defined order of elements. This means they will produce resulting
 *  parallel sequences in the same way sequential sequences do. However, the order
 *  in which they perform bulk operations on elements to produce results is not defined and is generally
 *  nondeterministic. If the higher-order functions given to them produce no sideeffects,
 *  then this won't be noticeable.
 *
 *  This trait defines a new, more general `split` operation and reimplements the `split`
 *  operation of `ParallelIterable` trait using the new `split` operation.
 *
 *  @author Aleksandar Prokopec
 *  @since 2.9
 */
trait ParSeqLike[+T, +Repr <: ParSeq[T], +Sequential <: Seq[T] with SeqLike[T, Sequential]]
extends scala.collection.GenSeqLike[T, Repr]
   with ParIterableLike[T, Repr, Sequential] {
self =>

  protected[this] type SuperParIterator = IterableSplitter[T]

  /** A more refined version of the iterator found in the `ParallelIterable` trait,
   *  this iterator can be split into arbitrary subsets of iterators.
   *
   *  @return       an iterator that can be split into subsets of precise size
   */
  protected[parallel] def splitter: SeqSplitter[T]

  override def iterator: PreciseSplitter[T] = splitter

  override def size = length

  /** Used to iterate elements using indices */
  protected abstract class Elements(start: Int, val end: Int) extends SeqSplitter[T] with BufferedIterator[T] {
    private var i = start

    def hasNext = i < end

    def next(): T = if (i < end) {
      val x = self(i)
      i += 1
      x
    } else Iterator.empty.next()

    def head = self(i)

    final def remaining = end - i

    def dup = new Elements(i, end) {}

    def split = psplit(remaining / 2, remaining - remaining / 2)

    def psplit(sizes: Int*) = {
      val incr = sizes.scanLeft(0)(_ + _)
      for ((from, until) <- incr.init zip incr.tail) yield {
        new Elements(start + from, (start + until) min end) {}
      }
    }

    override def toString = "Elements(" + start + ", " + end + ")"
  }

  /* ParallelSeq methods */

  /** Returns the length of the longest segment of elements starting at
   *  a given position satisfying some predicate.
   *
   *  $indexsignalling
   *
   *  The index flag is initially set to maximum integer value.
   *
   *  @param p     the predicate used to test the elements
   *  @param from  the starting offset for the search
   *  @return      the length of the longest segment of elements starting at `from` and
   *               satisfying the predicate
   */
  def segmentLength(p: T => Boolean, from: Int): Int = if (from >= length) 0 else {
    val realfrom = if (from < 0) 0 else from
    val ctx = new DefaultSignalling with AtomicIndexFlag
    ctx.setIndexFlag(Int.MaxValue)
    tasksupport.executeAndWaitResult(new SegmentLength(p, 0, splitter.psplitWithSignalling(realfrom, length - realfrom)(1) assign ctx))._1
  }

  /** Finds the first element satisfying some predicate.
   *
   *  $indexsignalling
   *
   *  The index flag is initially set to maximum integer value.
   *
   *  @param p     the predicate used to test the elements
   *  @param from  the starting offset for the search
   *  @return      the index `>= from` of the first element of this $coll that satisfies the predicate `p`,
   *               or `-1`, if none exists
   */
  def indexWhere(p: T => Boolean, from: Int): Int = if (from >= length) -1 else {
    val realfrom = if (from < 0) 0 else from
    val ctx = new DefaultSignalling with AtomicIndexFlag
    ctx.setIndexFlag(Int.MaxValue)
    tasksupport.executeAndWaitResult(new IndexWhere(p, realfrom, splitter.psplitWithSignalling(realfrom, length - realfrom)(1) assign ctx))
  }

  /** Finds the last element satisfying some predicate.
   *
   *  $indexsignalling
   *
   *  The index flag is initially set to minimum integer value.
   *
   *  @param p     the predicate used to test the elements
   *  @param end   the maximum offset for the search
   *  @return      the index `<= end` of the first element of this $coll that satisfies the predicate `p`,
   *               or `-1`, if none exists
   */
  def lastIndexWhere(p: T => Boolean, end: Int): Int = if (end < 0) -1 else {
    val until = if (end >= length) length else end + 1
    val ctx = new DefaultSignalling with AtomicIndexFlag
    ctx.setIndexFlag(Int.MinValue)
    tasksupport.executeAndWaitResult(new LastIndexWhere(p, 0, splitter.psplitWithSignalling(until, length - until)(0) assign ctx))
  }

  def reverse: Repr = {
    tasksupport.executeAndWaitResult(new Reverse(() => newCombiner, splitter) mapResult { _.resultWithTaskSupport })
  }

  def reverseMap[S, That](f: T => S)(implicit bf: CanBuildFrom[Repr, S, That]): That = if (bf(repr).isCombiner) {
    tasksupport.executeAndWaitResult(
      new ReverseMap[S, That](f, () => bf(repr).asCombiner, splitter) mapResult { _.resultWithTaskSupport }
    )
  } else setTaskSupport(seq.reverseMap(f)(bf2seq(bf)), tasksupport)
  /*bf ifParallel { pbf =>
    tasksupport.executeAndWaitResult(new ReverseMap[S, That](f, pbf, splitter) mapResult { _.result })
  } otherwise seq.reverseMap(f)(bf2seq(bf))*/

  /** Tests whether this $coll contains the given sequence at a given index.
   *
   *  $abortsignalling
   *
   *  @tparam S      the element type of `that` parallel sequence
   *  @param that    the parallel sequence this sequence is being searched for
   *  @param offset  the starting offset for the search
   *  @return        `true` if there is a sequence `that` starting at `offset` in this sequence, `false` otherwise
   */
  def startsWith[S](that: GenSeq[S], offset: Int): Boolean = that ifParSeq { pthat =>
    if (offset < 0 || offset >= length) offset == length && pthat.length == 0
    else if (pthat.length == 0) true
    else if (pthat.length > length - offset) false
    else {
      val ctx = new DefaultSignalling with VolatileAbort
      tasksupport.executeAndWaitResult(
        new SameElements(splitter.psplitWithSignalling(offset, pthat.length)(1) assign ctx, pthat.splitter)
      )
    }
  } otherwise seq.startsWith(that, offset)

  override def sameElements[U >: T](that: GenIterable[U]): Boolean = that ifParSeq { pthat =>
    val ctx = new DefaultSignalling with VolatileAbort
    length == pthat.length && tasksupport.executeAndWaitResult(new SameElements(splitter assign ctx, pthat.splitter))
  } otherwise seq.sameElements(that)

  /** Tests whether this $coll ends with the given parallel sequence.
   *
   *  $abortsignalling
   *
   *  @tparam S       the type of the elements of `that` sequence
   *  @param that     the sequence to test
   *  @return         `true` if this $coll has `that` as a suffix, `false` otherwise
   */
  def endsWith[S](that: GenSeq[S]): Boolean = that ifParSeq { pthat =>
    if (that.length == 0) true
    else if (that.length > length) false
    else {
      val ctx = new DefaultSignalling with VolatileAbort
      val tlen = that.length
      tasksupport.executeAndWaitResult(new SameElements(splitter.psplitWithSignalling(length - tlen, tlen)(1) assign ctx, pthat.splitter))
    }
  } otherwise seq.endsWith(that)

  def patch[U >: T, That](from: Int, patch: GenSeq[U], replaced: Int)(implicit bf: CanBuildFrom[Repr, U, That]): That = {
    val realreplaced = replaced min (length - from)
    if (patch.isParSeq && bf(repr).isCombiner && (size - realreplaced + patch.size) > MIN_FOR_COPY) {
      val that = patch.asParSeq
      val pits = splitter.psplitWithSignalling(from, replaced, length - from - realreplaced)
      val cfactory = combinerFactory(() => bf(repr).asCombiner)
      val copystart = new Copy[U, That](cfactory, pits(0))
      val copymiddle = wrap {
        val tsk = new that.Copy[U, That](cfactory, that.splitter)
        tasksupport.executeAndWaitResult(tsk)
      }
      val copyend = new Copy[U, That](cfactory, pits(2))
      tasksupport.executeAndWaitResult(((copystart parallel copymiddle) { _ combine _ } parallel copyend) { _ combine _ } mapResult {
        _.resultWithTaskSupport
      })
    } else patch_sequential(from, patch.seq, replaced)
  }

  private def patch_sequential[U >: T, That](fromarg: Int, patch: Seq[U], r: Int)(implicit bf: CanBuildFrom[Repr, U, That]): That = {
    val from = 0 max fromarg
    val b = bf(repr)
    val repl = (r min (length - from)) max 0
    val pits = splitter.psplitWithSignalling(from, repl, length - from - repl)
    b ++= pits(0)
    b ++= patch
    b ++= pits(2)
    setTaskSupport(b.result(), tasksupport)
  }

  def updated[U >: T, That](index: Int, elem: U)(implicit bf: CanBuildFrom[Repr, U, That]): That = if (bf(repr).isCombiner) {
    tasksupport.executeAndWaitResult(
      new Updated(index, elem, combinerFactory(() => bf(repr).asCombiner), splitter) mapResult {
        _.resultWithTaskSupport
      }
    )
  } else setTaskSupport(seq.updated(index, elem)(bf2seq(bf)), tasksupport)
  /*bf ifParallel { pbf =>
    tasksupport.executeAndWaitResult(new Updated(index, elem, pbf, splitter) mapResult { _.result })
  } otherwise seq.updated(index, elem)(bf2seq(bf))*/

  def +:[U >: T, That](elem: U)(implicit bf: CanBuildFrom[Repr, U, That]): That = {
    patch(0, mutable.ParArray(elem), 0)
  }

  def :+[U >: T, That](elem: U)(implicit bf: CanBuildFrom[Repr, U, That]): That = {
    patch(length, mutable.ParArray(elem), 0)
  }

  def padTo[U >: T, That](len: Int, elem: U)(implicit bf: CanBuildFrom[Repr, U, That]): That = if (length < len) {
    patch(length, new immutable.Repetition(elem, len - length), 0)
  } else patch(length, Nil, 0)

  override def zip[U >: T, S, That](that: GenIterable[S])(implicit bf: CanBuildFrom[Repr, (U, S), That]): That = if (bf(repr).isCombiner && that.isParSeq) {
    val thatseq = that.asParSeq
    tasksupport.executeAndWaitResult(
      new Zip(length min thatseq.length, combinerFactory(() => bf(repr).asCombiner), splitter, thatseq.splitter) mapResult {
        _.resultWithTaskSupport
      }
    )
  } else super.zip(that)(bf)

  /** Tests whether every element of this $coll relates to the
   *  corresponding element of another parallel sequence by satisfying a test predicate.
   *
   *  $abortsignalling
   *
   *  @param   that    the other parallel sequence
   *  @param   p       the test predicate, which relates elements from both sequences
   *  @tparam  S       the type of the elements of `that`
   *  @return          `true` if both parallel sequences have the same length and
   *                   `p(x, y)` is `true` for all corresponding elements `x` of this $coll
   *                   and `y` of `that`, otherwise `false`
   */
  def corresponds[S](that: GenSeq[S])(p: (T, S) => Boolean): Boolean = that ifParSeq { pthat =>
    val ctx = new DefaultSignalling with VolatileAbort
    length == pthat.length && tasksupport.executeAndWaitResult(new Corresponds(p, splitter assign ctx, pthat.splitter))
  } otherwise seq.corresponds(that)(p)

  def diff[U >: T](that: GenSeq[U]): Repr = sequentially {
    _ diff that
  }

  /** Computes the multiset intersection between this $coll and another sequence.
   *
   *  @param that   the sequence of elements to intersect with.
   *  @tparam U     the element type of `that` parallel sequence
   *  @return       a new collection of type `That` which contains all elements of this $coll
   *                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.
   *
   *  @usecase def intersect(that: Seq[T]): $Coll[T]
   *    @inheritdoc
   *
   *    $mayNotTerminateInf
   *
   *    @return       a new $coll which contains all elements of this $coll
   *                  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.
   */
  def intersect[U >: T](that: GenSeq[U]) = sequentially {
    _ intersect that
  }

  /** Builds a new $coll from this $coll without any duplicate elements.
   *  $willNotTerminateInf
   *
   *  @return  A new $coll which contains the first occurrence of every element of this $coll.
   */
  def distinct: Repr = sequentially {
    _.distinct
  }

  override def toString = seq.mkString(stringPrefix + "(", ", ", ")")

  override def toSeq = this.asInstanceOf[ParSeq[T]]

  @deprecated("use .seq.view", "2.11.0")
  override def view = seq.view

  /* tasks */

  protected[this] def down(p: IterableSplitter[_]) = p.asInstanceOf[SeqSplitter[T]]

  protected trait Accessor[R, Tp] extends super.Accessor[R, Tp] {
    protected[this] val pit: SeqSplitter[T]
  }

  protected trait Transformer[R, Tp] extends Accessor[R, Tp] with super.Transformer[R, Tp]

  protected[this] class SegmentLength(pred: T => Boolean, from: Int, protected[this] val pit: SeqSplitter[T])
  extends Accessor[(Int, Boolean), SegmentLength] {
    @volatile var result: (Int, Boolean) = null
    def leaf(prev: Option[(Int, Boolean)]) = if (from < pit.indexFlag) {
      val itsize = pit.remaining
      val seglen = pit.prefixLength(pred)
      result = (seglen, itsize == seglen)
      if (!result._2) pit.setIndexFlagIfLesser(from)
    } else result = (0, false)
    protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException
    override def split = {
      val pits = pit.splitWithSignalling
      for ((p, untilp) <- pits zip pits.scanLeft(0)(_ + _.remaining)) yield new SegmentLength(pred, from + untilp, p)
    }
    override def merge(that: SegmentLength) = if (result._2) result = (result._1 + that.result._1, that.result._2)
    override def requiresStrictSplitters = true
  }

  protected[this] class IndexWhere(pred: T => Boolean, from: Int, protected[this] val pit: SeqSplitter[T])
  extends Accessor[Int, IndexWhere] {
    @volatile var result: Int = -1
    def leaf(prev: Option[Int]) = if (from < pit.indexFlag) {
      val r = pit.indexWhere(pred)
      if (r != -1) {
        result = from + r
        pit.setIndexFlagIfLesser(from)
      }
    }
    protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException
    override def split = {
      val pits = pit.splitWithSignalling
      for ((p, untilp) <- pits zip pits.scanLeft(from)(_ + _.remaining)) yield new IndexWhere(pred, untilp, p)
    }
    override def merge(that: IndexWhere) = result = if (result == -1) that.result else {
      if (that.result != -1) result min that.result else result
    }
    override def requiresStrictSplitters = true
  }

  protected[this] class LastIndexWhere(pred: T => Boolean, pos: Int, protected[this] val pit: SeqSplitter[T])
  extends Accessor[Int, LastIndexWhere] {
    @volatile var result: Int = -1
    def leaf(prev: Option[Int]) = if (pos > pit.indexFlag) {
      val r = pit.lastIndexWhere(pred)
      if (r != -1) {
        result = pos + r
        pit.setIndexFlagIfGreater(pos)
      }
    }
    protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException
    override def split = {
      val pits = pit.splitWithSignalling
      for ((p, untilp) <- pits zip pits.scanLeft(pos)(_ + _.remaining)) yield new LastIndexWhere(pred, untilp, p)
    }
    override def merge(that: LastIndexWhere) = result = if (result == -1) that.result else {
      if (that.result != -1) result max that.result else result
    }
    override def requiresStrictSplitters = true
  }

  protected[this] class Reverse[U >: T, This >: Repr](cbf: () => Combiner[U, This], protected[this] val pit: SeqSplitter[T])
  extends Transformer[Combiner[U, This], Reverse[U, This]] {
    @volatile var result: Combiner[U, This] = null
    def leaf(prev: Option[Combiner[U, This]]) = result = pit.reverse2combiner(reuse(prev, cbf()))
    protected[this] def newSubtask(p: SuperParIterator) = new Reverse(cbf, down(p))
    override def merge(that: Reverse[U, This]) = result = that.result combine result
  }

  protected[this] class ReverseMap[S, That](f: T => S, pbf: () => Combiner[S, That], protected[this] val pit: SeqSplitter[T])
  extends Transformer[Combiner[S, That], ReverseMap[S, That]] {
    @volatile var result: Combiner[S, That] = null
    def leaf(prev: Option[Combiner[S, That]]) = result = pit.reverseMap2combiner(f, pbf())
    protected[this] def newSubtask(p: SuperParIterator) = new ReverseMap(f, pbf, down(p))
    override def merge(that: ReverseMap[S, That]) = result = that.result combine result
  }

  protected[this] class SameElements[U >: T](protected[this] val pit: SeqSplitter[T], val otherpit: SeqSplitter[U])
  extends Accessor[Boolean, SameElements[U]] {
    @volatile var result: Boolean = true
    def leaf(prev: Option[Boolean]) = if (!pit.isAborted) {
      result = pit.sameElements(otherpit)
      if (!result) pit.abort()
    }
    protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException
    override def split = {
      val fp = pit.remaining / 2
      val sp = pit.remaining - fp
      for ((p, op) <- pit.psplitWithSignalling(fp, sp) zip otherpit.psplitWithSignalling(fp, sp)) yield new SameElements(p, op)
    }
    override def merge(that: SameElements[U]) = result = result && that.result
    override def requiresStrictSplitters = true
  }

  protected[this] class Updated[U >: T, That](pos: Int, elem: U, pbf: CombinerFactory[U, That], protected[this] val pit: SeqSplitter[T])
  extends Transformer[Combiner[U, That], Updated[U, That]] {
    @volatile var result: Combiner[U, That] = null
    def leaf(prev: Option[Combiner[U, That]]) = result = pit.updated2combiner(pos, elem, pbf())
    protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException
    override def split = {
      val pits = pit.splitWithSignalling
      for ((p, untilp) <- pits zip pits.scanLeft(0)(_ + _.remaining)) yield new Updated(pos - untilp, elem, pbf, p)
    }
    override def merge(that: Updated[U, That]) = result = result combine that.result
    override def requiresStrictSplitters = true
  }

  protected[this] class Zip[U >: T, S, That](len: Int, cf: CombinerFactory[(U, S), That], protected[this] val pit: SeqSplitter[T], val otherpit: SeqSplitter[S])
  extends Transformer[Combiner[(U, S), That], Zip[U, S, That]] {
    @volatile var result: Result = null
    def leaf(prev: Option[Result]) = result = pit.zip2combiner[U, S, That](otherpit, cf())
    protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException
    override def split = {
      val fp = len / 2
      val sp = len - len / 2
      val pits = pit.psplitWithSignalling(fp, sp)
      val opits = otherpit.psplitWithSignalling(fp, sp)
      Seq(
        new Zip(fp, cf, pits(0), opits(0)),
        new Zip(sp, cf, pits(1), opits(1))
      )
    }
    override def merge(that: Zip[U, S, That]) = result = result combine that.result
  }

  protected[this] class Corresponds[S](corr: (T, S) => Boolean, protected[this] val pit: SeqSplitter[T], val otherpit: SeqSplitter[S])
  extends Accessor[Boolean, Corresponds[S]] {
    @volatile var result: Boolean = true
    def leaf(prev: Option[Boolean]) = if (!pit.isAborted) {
      result = pit.corresponds(corr)(otherpit)
      if (!result) pit.abort()
    }
    protected[this] def newSubtask(p: SuperParIterator) = throw new UnsupportedOperationException
    override def split = {
      val fp = pit.remaining / 2
      val sp = pit.remaining - fp
      for ((p, op) <- pit.psplitWithSignalling(fp, sp) zip otherpit.psplitWithSignalling(fp, sp)) yield new Corresponds(corr, p, op)
    }
    override def merge(that: Corresponds[S]) = result = result && that.result
    override def requiresStrictSplitters = true
  }
}