Iterators are data structures that allow to iterate over a sequence
of elements.

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 advances 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 collection to a string builder.
The written text consists of the string representations (w.r.t. the method
toString) of all elements of this collection without any separator string.

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

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

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

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

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.

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.

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.

The implementation may allocate temporary storage for elements
iterated by one iterator but not yet by the other.

,

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.

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

Tests whether the argument (that) 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.

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.

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

Folds the elements of this collection using the specified associative binary operator.
The default implementation in IterableOnce is equivalent to foldLeft but may be
overridden for more efficient traversal orders.

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

Note: will not terminate for infinite-sized collections.

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 the fold operator op between all the elements and z, or z if this collection is empty.

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.

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 collection. In the resulting string
the string representations (w.r.t. the method toString)
of all elements of this collection follow each other without any
separator string.

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

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

Delegates to addString, which can be overridden.

start

the starting string.

sep

the separator string.

end

the ending string.

returns

a string representation of this collection. 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 collection are separated by
the string sep.

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

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.

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.

Returns an iterator which presents a "sliding window" view of
this iterator.

Returns an iterator which presents a "sliding window" view of
this iterator. The first argument is the window size, and
the second argument step is how far to advance the window
on each iteration. The step defaults to 1.

The default GroupedIterator can be configured to either
pad a partial result to size size or suppress the partial
result entirely.

An iterator producing Seq[B]s of size size, except the
last element (which may be the only element) will be truncated
if there are fewer than size elements remaining to be grouped.
This behavior can be configured.

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 iterators that were returned. Using the old iterator
is undefined, subject to change, and may result in changes to the new
iterators as well.

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 Stepper enables creating a Java stream to operate on the collection, see
scala.jdk.StreamConverters. For collections holding primitive values, the Stepper can be
used as an iterator which doesn't box the elements.

The implicit StepperShape parameter defines the resulting Stepper type according to the
element type of this collection.

For collections of Int, Short, Byte or Char, an IntStepper is returned

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.

Applies a side-effecting function to each element in this collection.
Strict collections will apply f to their elements immediately, while lazy collections
like Views and LazyLists will only apply f on each element if and when that element
is evaluated, and each time that element is evaluated.

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.

Tests whether this iterator is known to have a finite size.
All strict collections are known to have finite size. For a non-strict
collection such as Stream, the predicate returns true if all
elements have been computed. It returns false if the stream is
not yet evaluated to the end. Non-empty Iterators usually return
false even if they were created from a collection with a known
finite size.

Note: many collection methods will not work on collections of infinite sizes.
The typical failure mode is an infinite loop. These methods always attempt a
traversal without checking first that hasDefiniteSize returns true.
However, checking hasDefiniteSize can provide an assurance that size is
well-defined and non-termination is not a concern.

returns

true if this collection is known to have finite size,
false otherwise.