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.
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
.
Tests whether this iterator can provide another element.
Tests whether this iterator can provide another element.
true
if a subsequent call to next
will yield an element,
false
otherwise.
Reuse: The iterator remains valid for further use whatever result is returned.
Returns next element of iterator without advancing beyond it.
Produces the next element of this iterator.
Produces the next element of this iterator.
the next element of this iterator, if hasNext
is true
,
undefined behavior otherwise.
Reuse: The iterator remains valid for further use whatever result is returned.
[use case] Concatenates this iterator with another.
Concatenates this iterator with another.
the other iterator
a new iterator that first yields the values produced by this
iterator followed by the values produced by iterator that
.
Applies a binary operator to a start value and all elements of this traversable or iterator, going left to right.
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.
the result type of the binary operator.
the start value.
the binary operator.
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.
Applies a binary operator to all elements of this traversable or iterator and a start value, going right to left.
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
the result type of the binary operator.
the start value
the binary operator
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.
Appends all elements of this traversable or iterator to a string builder.
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
the string builder to which elements are appended.
the string builder b
to which elements were appended.
Appends all elements of this traversable or iterator to a string builder using a separator string.
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
the string builder to which elements are appended.
the separator string.
the string builder b
to which elements were appended.
Appends all elements of this traversable or iterator to a string builder using start, end, and separator strings.
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)
the string builder to which elements are appended.
the starting string.
the separator string.
the ending string.
the string builder b
to which elements were appended.
Aggregates the results of applying an operator to subsequent elements.
Aggregates the results of applying an operator to subsequent elements.
This is a more general form of fold
and reduce
. It is similar to
foldLeft
in that it doesn't require the result to be a supertype of the
element type. In addition, it allows parallel collections to be processed
in chunks, and then combines the intermediate results.
aggregate
splits the traversable or iterator into partitions and processes each
partition by sequentially applying seqop
, starting with z
(like
foldLeft
). Those intermediate results are then combined by using
combop
(like fold
). The implementation of this operation may operate
on an arbitrary number of collection partitions (even 1), so combop
may
be invoked an arbitrary number of times (even 0).
As an example, consider summing up the integer values of a list of chars.
The initial value for the sum is 0. First, seqop
transforms each input
character to an Int and adds it to the sum (of the partition). Then,
combop
just needs to sum up the intermediate results of the partitions:
List('a', 'b', 'c').aggregate(0)({ (sum, ch) => sum + ch.toInt }, { (p1, p2) => p1 + p2 })
the type of accumulated results
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
an operator used to accumulate results within a partition
an associative operator used to combine results from different partitions
Creates a buffered iterator from this iterator.
Creates a buffered iterator from this iterator.
a buffered iterator producing the same values as this iterator.
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.
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.
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.
the partial function which filters and maps the iterator.
a new iterator which yields each value x
produced by this iterator for
which pf
is defined the image pf(x)
.
(Changed in version 2.8.0) collect
has changed. The previous behavior can be reproduced with toSeq
.
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.
Finds the first element of the traversable or iterator for which the given partial function is defined, and applies the partial function to it.
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.
the partial function
an option value containing pf applied to the first
value for which it is defined, or None
if none exists.
Seq("a", 1, 5L).collectFirst({ case x: Int => x*10 }) = Some(10)
Tests whether this iterator contains a given value as an element.
Tests whether this iterator contains a given value as an element.
Note: may not terminate for infinite iterators.
the element to test.
true
if this iterator produces some value that is
is equal (as determined by ==
) to elem
, false
otherwise.
Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.
[use case] Copies selected values produced by this iterator to an array.
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.
the array to fill.
the starting index.
the maximal number of elements to copy.
[use case] Copies the elements of this traversable or iterator to an array.
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.
the array to fill.
[use case] Copies the elements of this traversable or iterator to an array.
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.
the array to fill.
the starting index.
Copies all elements of this traversable or iterator to a buffer.
Copies all elements of this traversable or iterator to a buffer.
Note: will not terminate for infinite-sized collections.
The buffer to which elements are copied.
Tests whether every element of this iterator relates to the corresponding element of another collection by satisfying a test predicate.
Tests whether every element of this iterator relates to the corresponding element of another collection by satisfying a test predicate.
the type of the elements of that
the other collection
the test predicate, which relates elements from both collections
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
Counts the number of elements in the traversable or iterator which satisfy a predicate.
Counts the number of elements in the traversable or iterator which satisfy a predicate.
the predicate used to test elements.
the number of elements satisfying the predicate p
.
Advances this iterator past the first n elements, or the length of the iterator, whichever is smaller.
Advances this iterator past the first n elements, or the length of the iterator, whichever is smaller.
the number of elements to drop
an iterator which produces all values of the current iterator, except
it omits the first n
values.
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.
Skips longest sequence of elements of this iterator which satisfy given
predicate p
, and returns an iterator of the remaining elements.
Skips longest sequence of elements of this iterator which satisfy given
predicate p
, and returns an iterator of the remaining elements.
the predicate used to skip elements.
an iterator consisting of the remaining elements
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.
Creates two new iterators that both iterate over the same elements as this iterator (in the same order).
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.
a pair of iterators
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.
Tests whether a predicate holds for some of the values produced by this iterator.
Tests whether a predicate holds for some of the values produced by this iterator.
Note: may not terminate for infinite iterators.
the predicate used to test elements.
true
if the given predicate p
holds for some of the values
produced by this iterator, otherwise false
.
Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.
Returns an iterator over all the elements of this iterator that satisfy the predicate p
.
Returns an iterator over all the elements of this iterator that satisfy the predicate p
.
The order of the elements is preserved.
the predicate used to test values.
an iterator which produces those values of this iterator which satisfy the predicate p
.
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.
Creates an iterator over all the elements of this iterator which do not satisfy a predicate p.
Creates an iterator over all the elements of this iterator which do not satisfy a predicate p.
the predicate used to test values.
an iterator which produces those values of this iterator which do not satisfy the predicate p
.
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.
Finds the first value produced by the iterator satisfying a predicate, if any.
Finds the first value produced by the iterator satisfying a predicate, if any.
Note: may not terminate for infinite iterators.
the predicate used to test values.
an option value containing the first value produced by the iterator that satisfies
predicate p
, or None
if none exists.
Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.
Creates a new iterator by applying a function to all values produced by this iterator and concatenating the results.
Creates a new iterator by applying a function to all values produced by this iterator and concatenating the results.
the function to apply on each element.
the iterator resulting from applying the given iterator-valued function
f
to each value produced by this iterator and concatenating the results.
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.
Folds the elements of this traversable or iterator using the specified associative binary operator.
Folds the elements of this traversable or iterator using the specified associative binary operator.
The order in which operations are performed on elements is unspecified and may be nondeterministic.
Note: will not terminate for infinite-sized collections.
a type parameter for the binary operator, a supertype of A
.
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).
a binary operator that must be associative.
the result of applying the fold operator op
between all the elements and z
, or z
if this traversable or iterator is empty.
Applies a binary operator to a start value and all elements of this traversable or iterator, going left to right.
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.
the result type of the binary operator.
the start value.
the binary operator.
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.
Applies a binary operator to all elements of this traversable or iterator and a start value, going right to left.
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.
the result type of the binary operator.
the start value.
the binary operator.
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.
Tests whether a predicate holds for all values produced by this iterator.
Tests whether a predicate holds for all values produced by this iterator.
Note: may not terminate for infinite iterators.
the predicate used to test elements.
true
if the given predicate p
holds for all values
produced by this iterator, otherwise false
.
Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.
[use case] Applies a function f
to all values produced by this iterator.
Applies a function f
to all values produced by this iterator.
the function that is applied for its side-effect to every element.
The result of function f
is discarded.
Returns an iterator which groups this iterator into fixed size blocks.
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
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.
Tests whether this Iterator has a known size.
Tests whether this Iterator has a known size.
true
for empty Iterators, false
otherwise.
Reuse: The iterator remains valid for further use whatever result is returned.
Returns the index of the first occurrence of the specified object in this iterable object.
Returns the index of the first occurrence of the specified object in this iterable object.
Note: may not terminate for infinite iterators.
element to search for.
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.
Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.
Returns the index of the first produced value satisfying a predicate, or -1.
Returns the index of the first produced value satisfying a predicate, or -1.
Note: may not terminate for infinite iterators.
the predicate to test values
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.
Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.
Tests whether this iterator is empty.
Tests whether this iterator is empty.
true
if hasNext is false, false
otherwise.
Reuse: The iterator remains valid for further use whatever result is returned.
Tests whether this Iterator can be repeatedly traversed.
Tests whether this Iterator can be repeatedly traversed.
false
Reuse: The iterator remains valid for further use whatever result is returned.
Returns the number of elements in this iterator.
Returns the number of elements in this iterator.
Note: will not terminate for infinite iterators.
Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change.
Creates a new iterator that maps all produced values of this iterator to new values using a transformation function.
Creates a new iterator that maps all produced values of this iterator to new values using a transformation function.
the transformation function
a new iterator which transforms every value produced by this
iterator by applying the function f
to it.
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.
[use case] Finds the largest element.
Finds the largest element.
the largest element of this traversable or iterator.
[use case] Finds the first element which yields the largest value measured by function f.
Finds the first element which yields the largest value measured by function f.
The result type of the function f.
The measuring function.
the first element of this traversable or iterator with the largest value measured by function f.
[use case] Finds the smallest element.
Finds the smallest element.
the smallest element of this traversable or iterator
[use case] Finds the first element which yields the smallest value measured by function f.
Finds the first element which yields the smallest value measured by function f.
The result type of the function f.
The measuring function.
the first element of this traversable or iterator with the smallest value measured by function f.
Displays all elements of this traversable or iterator in a string.
Displays all elements of this traversable or iterator in a string.
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 follow each other without any
separator string.
Displays all elements of this traversable or iterator in a string using a separator string.
Displays all elements of this traversable or iterator in a string using a separator string.
the separator string.
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
.
List(1, 2, 3).mkString("|") = "1|2|3"
Displays all elements of this traversable or iterator in a string using start, end, and separator strings.
Displays all elements of this traversable or iterator in a string using start, end, and separator strings.
the starting string.
the separator string.
the ending string.
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
.
List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"
Tests whether the traversable or iterator is not empty.
Tests whether the traversable or iterator is not empty.
true
if the traversable or iterator contains at least one element, false
otherwise.
[use case] Appends an element value to this iterator until a given target length is reached.
Appends an element value to this iterator until a given target length is reached.
the target length
the padding value
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
.
Partitions this iterator in two iterators according to a predicate.
Partitions this iterator in two iterators according to a predicate.
the predicate on which to partition
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.
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.
Returns this iterator with patched values.
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.
The start index from which to patch
The iterator of patch values
The number of values in the original iterator that are replaced by the patch.
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.
[use case] Multiplies up the elements of this collection.
Multiplies up the elements of this collection.
the product of all elements in this traversable or iterator of numbers of type Int
.
Instead of Int
, any other type T
with an implicit Numeric[T]
implementation
can be used as element type of the traversable or iterator and as result type of product
.
Examples of such types are: Long
, Float
, Double
, BigInt
.
Reduces the elements of this traversable or iterator using the specified associative binary operator.
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.
A type parameter for the binary operator, a supertype of A
.
A binary operator that must be associative.
The result of applying reduce operator op
between all the elements if the traversable or iterator is nonempty.
UnsupportedOperationException
if this traversable or iterator is empty.
Applies a binary operator to all elements of this traversable or iterator, going left to right.
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.
the result type of the binary operator.
the binary operator.
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.
UnsupportedOperationException
if this traversable or iterator is empty.
Optionally applies a binary operator to all elements of this traversable or iterator, going left to right.
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.
the result type of the binary operator.
the binary operator.
an option value containing the result of reduceLeft(op)
if this traversable or iterator is nonempty,
None
otherwise.
Reduces the elements of this traversable or iterator, if any, using the specified associative binary operator.
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.
A type parameter for the binary operator, a supertype of A
.
A binary operator that must be associative.
An option value containing result of applying reduce operator op
between all
the elements if the collection is nonempty, and None
otherwise.
Applies a binary operator to all elements of this traversable or iterator, going right to left.
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.
the result type of the binary operator.
the binary operator.
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.
UnsupportedOperationException
if this traversable or iterator is empty.
Optionally applies a binary operator to all elements of this traversable or iterator, going right to left.
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.
the result type of the binary operator.
the binary operator.
an option value containing the result of reduceRight(op)
if this traversable or iterator is nonempty,
None
otherwise.
Tests if another iterator produces the same values as this one.
Tests if another iterator produces the same values as this one.
Note: will not terminate for infinite iterators.
the other iterator
true
, if both iterators produce the same elements in the same order, false
otherwise.
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.
Produces a collection containing cumulative results of applying the operator going left to right.
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.
the type of the elements in the resulting collection
the initial value
the binary operator applied to the intermediate result and the element
iterator with intermediate results
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.
Produces a collection containing cumulative results of applying the operator going right to left.
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.
the type of the elements in the resulting collection
the initial value
the binary operator applied to the intermediate result and the element
iterator with intermediate results
Iterator(1, 2, 3, 4).scanRight(0)(_ + _).toList == List(10, 9, 7, 4, 0)
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.
A version of this collection with all of the operations implemented sequentially (i.e., in a single-threaded manner).
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.
a sequential view of the collection.
The size of this traversable or iterator.
The size of this traversable or iterator.
Note: will not terminate for infinite-sized collections.
the number of elements in this traversable or iterator.
Creates an iterator returning an interval of the values produced by this iterator.
Creates an iterator returning an interval of the values produced by this iterator.
the index of the first element in this iterator which forms part of the slice.
the index of the first element following the slice.
an iterator which advances this iterator past the first from
elements using drop
,
and then takes until - from
elements, using take
.
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.
Returns an iterator which presents a "sliding window" view of another iterator.
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
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.
Splits this Iterator into a prefix/suffix pair according to a predicate.
Splits this Iterator into a prefix/suffix pair according to a predicate.
the test predicate
a pair of Iterators consisting of the longest prefix of this
whose elements all satisfy p
, and the rest of the Iterator.
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.
[use case] Sums up the elements of this collection.
Sums up the elements of this collection.
the sum of all elements in this traversable or iterator of numbers of type Int
.
Instead of Int
, any other type T
with an implicit Numeric[T]
implementation
can be used as element type of the traversable or iterator and as result type of sum
.
Examples of such types are: Long
, Float
, Double
, BigInt
.
Selects first n values of this iterator.
Selects first n values of this iterator.
the number of values to take
an iterator producing only of the first n
values of this iterator, or else the
whole iterator, if it produces fewer than n
values.
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.
Takes longest prefix of values produced by this iterator that satisfy a predicate.
Takes longest prefix of values produced by this iterator that satisfy a predicate.
The predicate used to test elements.
An iterator returning the values produced by this iterator, until
this iterator produces a value that does not satisfy
the predicate p
.
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.
[use case] Converts this traversable or iterator into another by copying all elements.
Converts this traversable or iterator into another by copying all elements.
Note: will not terminate for infinite iterators.
The collection type to build.
a new collection containing all elements of this traversable or iterator.
[use case] Converts this traversable or iterator to an array.
Converts this traversable or iterator to an array.
Note: will not terminate for infinite iterators.
an array containing all elements of this traversable or iterator.
An ClassTag
must be available for the element type of this traversable or iterator.
Uses the contents of this traversable or iterator to create a new mutable buffer.
Uses the contents of this traversable or iterator to create a new mutable buffer.
Note: will not terminate for infinite-sized collections.
a buffer containing all elements of this traversable or iterator.
Converts this traversable or iterator to an indexed sequence.
Converts this traversable or iterator to an indexed sequence.
Note: will not terminate for infinite-sized collections.
an indexed sequence containing all elements of this traversable or iterator.
Converts this traversable or iterator to an iterable collection.
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.
an Iterable
containing all elements of this traversable or iterator.
Returns an Iterator over the elements in this traversable or iterator.
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.
an Iterator containing all elements of this traversable or iterator.
Converts this traversable or iterator to a list.
Converts this traversable or iterator to a list.
Note: will not terminate for infinite-sized collections.
a list containing all elements of this traversable or iterator.
[use case] Converts this traversable or iterator to a map.
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.
a map of type immutable.Map[T, U]
containing all key/value pairs of type (T, U)
of this traversable or iterator.
Converts this traversable or iterator to a sequence.
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.
a sequence containing all elements of this traversable or iterator.
Converts this traversable or iterator to a set.
Converts this traversable or iterator to a set.
Note: will not terminate for infinite-sized collections.
a set containing all elements of this traversable or iterator.
Converts this traversable or iterator to a stream.
Converts this traversable or iterator to a stream.
a stream containing all elements of this traversable or iterator.
Converts this iterator to a string.
Converts this iterator to a string.
"empty iterator"
or "non-empty iterator"
, depending on
whether or not the iterator is empty.
Reuse: The iterator remains valid for further use whatever result is returned.
Converts this traversable or iterator to an unspecified Traversable.
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.
a Traversable containing all elements of this traversable or iterator.
Converts this traversable or iterator to a Vector.
Converts this traversable or iterator to a Vector.
Note: will not terminate for infinite-sized collections.
a vector containing all elements of this traversable or iterator.
Creates an iterator over all the elements of this iterator that
satisfy the predicate p
.
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.
the predicate used to test values.
an iterator which produces those values of this iterator which satisfy the predicate p
.
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.
Creates an iterator formed from this iterator and another iterator by combining corresponding values in pairs.
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.
The iterator providing the second half of each result pair
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
.
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.
[use case] Creates an iterator formed from this iterator and another iterator by combining corresponding elements in pairs.
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.
iterator that
may have a different length
as the self iterator.
element thisElem
is used to fill up the
resulting iterator if the self iterator is shorter than
that
element thatElem
is used to fill up the
resulting iterator if that
is shorter than
the self iterator
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.
Creates an iterator that pairs each element produced by this iterator with its index, counting from 0.
Creates an iterator that pairs each element produced by this iterator with its index, counting from 0.
a new iterator containing pairs consisting of corresponding elements of this iterator and their indices.
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.
Buffered iterators are iterators which provide a method
head
that inspects the next element without discarding it.2.8
2.8