Iterators are data structures that allow to iterate over a sequence
of elements. They have a hasNext method for checking
if there is a next element available, and a next method
which returns the next element and discards it from the iterator.

An iterator is mutable: most operations on it change its state. While it is often used
to iterate through the elements of a collection, it can also be used without
being backed by any collection (see constructors on the companion object).

It is of particular importance to note that, unless stated otherwise, one should never
use an iterator after calling a method on it. The two most important exceptions
are also the sole abstract methods: next and hasNext.

Both these methods can be called any number of times without having to discard the
iterator. Note that even hasNext may cause mutation -- such as when iterating
from an input stream, where it will block until the stream is closed or some
input becomes available.

Consider this example for safe and unsafe use:

def f[A](it: Iterator[A]) = {
if (it.hasNext) { // Safe to reuse "it" after "hasNext"
it.next // Safe to reuse "it" after "next"val remainder = it.drop(2) // it is *not* safe to use "it" again after this line!
remainder.take(2) // it is *not* safe to use "remainder" after this line!
} else it
}

Equivalent to x.hashCode except for boxed numeric types and null.
For numerics, it returns a hash value which is consistent
with value equality: if two value type instances compare
as true, then ## will produce the same hash value for each
of them.
For null returns a hashcode where null.hashCode throws a
NullPointerException.

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.

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.

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.

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

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 has similar
semantics, but does not require the result to be a supertype of the
element type. It traverses the elements in different partitions
sequentially, using seqop to update the result, and then applies
combop to results from different partitions. The implementation of
this operation may operate on an arbitrary number of collection
partitions, so combop may be invoked an arbitrary number of times.

For example, one might want to process some elements and then produce
a Set. In this case, seqop would process an element and append it
to the list, while combop would concatenate two lists from different
partitions together. The initial value z would be an empty set.

pc.aggregate(Set[Int]())(_ += process(_), _ ++ _)

Another example is calculating geometric mean from a collection of doubles
(one would typically require big doubles for this).

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)

seqop

an operator used to accumulate results within a partition

combop

an associative operator used to combine results from different partitions

final defasInstanceOf[T0]: T0

Cast the receiver object to be of type T0.

Cast the receiver object to be of type T0.

Note that the success of a cast at runtime is modulo Scala's erasure semantics.
Therefore the expression 1.asInstanceOf[String] will throw a ClassCastException at
runtime, while the expression List(1).asInstanceOf[List[String]] will not.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the requested type.

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.

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

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.

[use case] Copies selected values produced by this iterator to an array.

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

Copies values 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 array is reached.

Copies values 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 array is reached.

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.

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.

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.

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.

p

the predicate used to skip elements.

returns

an iterator consisting of the remaining elements

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.

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.

returns

a pair of iterators

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.

Tests whether the argument (arg0) is a reference to the receiver object (this).

Tests whether the argument (arg0) is a reference to the receiver object (this).

The eq method implements an equivalence relation on
non-null instances of AnyRef, and has three additional properties:

It is consistent: for any non-null instances x and y of type AnyRef, multiple invocations of
x.eq(y) consistently returns true or consistently returns false.

For any non-null instance x of type AnyRef, x.eq(null) and null.eq(x) returns false.

null.eq(null) returns true.

When overriding the equals or hashCode methods, it is important to ensure that their behavior is
consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2), they
should be equal to each other (o1 == o2) and they should hash to the same value (o1.hashCode == o2.hashCode).

returns

true if the argument is a reference to the receiver object; false otherwise.

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.

p

the predicate used to test values.

returns

an iterator which produces those values of this iterator which satisfy the predicate p.

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.

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.

p

the predicate used to test values.

returns

an iterator which produces those values of this iterator which do not satisfy the predicate p.

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.

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.

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.

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.

deffold[A1 >: A](z: A1)(op: (A1, A1) ⇒ A1): A1

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.

A1

a type parameter for the binary operator, a supertype of A.

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 fold operator op between all the elements and z

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.

Note that the result of the test is modulo Scala's erasure semantics.
Therefore the expression 1.isInstanceOf[String] will return false, while the
expression List(1).isInstanceOf[List[String]] will return true.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the specified type.

returns

true if the receiver object is an instance of erasure of type T0; false otherwise.

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.

f

the transformation function

returns

a new iterator which transforms every value produced by this
iterator by applying the function f to it.

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.

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.

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.

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.

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.

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.

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 number of values in the original iterator that are replaced by the patch.

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.

defproduct: A

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

[use case]

Multiplies up the elements of this collection.

returns

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.

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

Produces a collection containing cummulative 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

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.

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 returning an interval of the values produced by this iterator.

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

from

the index of the first element in this iterator which forms part of the slice.

until

the index of the first element following the slice.

returns

an iterator which advances this iterator past the first from elements using drop,
and then takes until - from elements, using take.

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.

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:

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.

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.

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.

defsum: A

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

[use case]

Sums up the elements of this collection.

returns

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.

final defsynchronized[T0](arg0: ⇒ T0): T0

an iterator producing only of the first n values of this iterator, or else the
whole iterator, if it produces fewer than n values.

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.

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.

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.

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.

defto[Col[_]]: Col[A]

[use case] Converts this traversable or iterator into another by copying all elements.

[use case]

Converts this traversable or iterator into another by copying all elements.

Note: will not terminate for infinite iterators.

Col

The collection type to build.

returns

a new collection containing all elements of this traversable or iterator.

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

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.

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.

p

the predicate used to test values.

returns

an iterator which produces those values of this iterator which satisfy the predicate p.

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.

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.

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.

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.

[use case] Creates an iterator formed from this iterator and another iterator
by combining corresponding elements in pairs.

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

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.

returns

a new iterator containing pairs consisting of
corresponding elements of this iterator and their indices.

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.

This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.To access this member you can use a type ascription:

This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.To access this member you can use a type ascription:

This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.To access this member you can use a type ascription:

This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.To access this member you can use a type ascription: