Class scala.collection.AbstractIterator
abstract class
AbstractIterator[+A] extends
Iterator[A]
Explicit instantiation of the Iterator
trait to reduce class file size in subclasses.
Supertypes | |
---|---|
Known subtypes |
Inherited classlikes
Source
class
GroupedIterator[B >: A](self:
Iterator[B], size:
Int, step:
Int) extends
AbstractIterator[
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
.
Inherited from | Iterator |
---|
Inherited methods
Source@inline
Inherited from | Iterator |
---|
Source@inline
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.
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
Value parameters |
|
---|---|
Returns | the string builder |
Inherited from | IterableOnceOps |
Source@inline
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
.
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
Value parameters |
|
---|---|
Returns | the string builder |
Inherited from | IterableOnceOps |
Source
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
.
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)
Value parameters |
|
---|---|
Returns | the string builder |
Inherited from | IterableOnceOps |
Source
def
buffered:
BufferedIterator[A]
Creates a buffered iterator from this iterator.
Returns | a buffered iterator producing the same values as this iterator. |
---|---|
See also | |
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. |
Inherited from | Iterator |
Source
Inherited from | Iterator |
---|
Source
Finds the first element of the collection 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.
Value parameters |
|
---|---|
Returns | an option value containing pf applied to the first value for which it is defined, or |
Example |
|
Inherited from | IterableOnceOps |
Source
Inherited from | Iterator |
---|
Source
Tests whether this iterator contains a given value as an element.
Note: may not terminate for infinite iterators.
Value parameters |
|
---|---|
Returns |
|
Note | Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change. |
Inherited from | Iterator |
Source
Copy elements to an array, returning the number of elements written.
Fills the given array xs
starting at index start
with at most len
elements of this collection.
Copying will stop once either all the elements of this collection have been copied, or the end of the array is reached, or len
elements have been copied.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the number of elements written to the array |
Note | Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change. |
Inherited from | IterableOnceOps |
Source@deprecatedOverriding("This should always forward to the 3-arg version of this method", since = "2.13.4")
Copy elements to an array, returning the number of elements written.
Fills the given array xs
starting at index start
with values of this collection.
Copying will stop once either all the elements of this collection have been copied, or the end of the array is reached.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the number of elements written to the array |
Note | Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change. |
Inherited from | IterableOnceOps |
Source@deprecatedOverriding("This should always forward to the 3-arg version of this method", since = "2.13.4")
Copy elements to an array, returning the number of elements written.
Fills the given array xs
starting at index start
with values of this collection.
Copying will stop once either all the elements of this collection have been copied, or the end of the array is reached.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the number of elements written to the array |
Note | Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change. |
Inherited from | IterableOnceOps |
Source
Tests whether every element of this collection's iterator relates to the corresponding element of another collection by satisfying a test predicate.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns |
|
Inherited from | IterableOnceOps |
Source
Counts the number of elements in the collection which satisfy a predicate.
Note: will not terminate for infinite-sized collections.
Value parameters |
|
---|---|
Returns | the number of elements satisfying the predicate |
Inherited from | IterableOnceOps |
Source
Builds a new iterator from this one without any duplicated elements on it.
Returns | iterator with distinct elements |
---|---|
Note | Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change. |
Inherited from | Iterator |
Source
def
distinctBy[B](f: A => B):
Iterator[A]
Builds a new iterator from this one without any duplicated elements as determined by ==
after applying the transforming function f
.
Type parameters |
|
---|---|
Value parameters |
|
Returns | iterator with distinct elements |
Note | Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change. |
Inherited from | Iterator |
Source
Inherited from | Iterator |
---|
Source
Inherited from | Iterator |
---|
Source
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 | 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. |
Inherited from | Iterator |
Source
Tests whether a predicate holds for at least one element of this collection.
Note: may not terminate for infinite-sized collections.
Value parameters |
|
---|---|
Returns |
|
Inherited from | IterableOnceOps |
Source
Inherited from | Iterator |
---|
Source
Inherited from | Iterator |
---|
Source
Finds the first element of the collection satisfying a predicate, if any.
Note: may not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered.
Value parameters |
|
---|---|
Returns | an option value containing the first element in the collection that satisfies |
Inherited from | IterableOnceOps |
Source
Inherited from | Iterator |
---|
Source
Inherited from | Iterator |
---|
Source
def
fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1
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.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the result of applying the fold operator |
Inherited from | IterableOnceOps |
Source
def
foldLeft[B](z: B)(op: (B, A) => B): B
Applies a binary operator to a start value and all elements of this collection, 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.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the result of inserting |
Inherited from | IterableOnceOps |
Source
def
foldRight[B](z: B)(op: (A, B) => B): B
Applies a binary operator to all elements of this collection 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.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the result of inserting |
Inherited from | IterableOnceOps |
Source
Tests whether a predicate holds for all elements of this collection.
Note: may not terminate for infinite-sized collections.
Value parameters |
|
---|---|
Returns |
|
Inherited from | IterableOnceOps |
Source
Apply f
to each element for its side effects Note: [U] parameter needed to help scalac's type inference.
Inherited from | IterableOnceOps |
---|
Source
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
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. |
---|---|
Inherited from | Iterator |
Source
Check if there is a next element available.
Returns |
|
---|---|
Note | Reuse: The iterator remains valid for further use whatever result is returned. |
Inherited from | Iterator |
Source
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.
Value parameters |
|
---|---|
Returns | the index |
Note | Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change. |
Inherited from | Iterator |
Source
Returns the index of the first occurrence of the specified object in this iterable object.
Note: may not terminate for infinite iterators.
Value parameters |
|
---|---|
Returns | the index of the first occurrence of |
Note | Reuse: After calling this method, one should discard the iterator it was called on. Using it is undefined and subject to change. |
Inherited from | Iterator |
Source
Inherited from | Iterator |
---|
Source@deprecatedOverriding("isEmpty is defined as !hasNext; override hasNext instead", "2.13.0")
Definition Classes | Iterator -> IterableOnceOps |
---|---|
Inherited from | Iterator |
Source
Tests whether this collection can be repeatedly traversed. Always true for Iterables and false for Iterators unless overridden.
Returns |
|
---|---|
Inherited from | IterableOnceOps |
Source@inline
Inherited from | Iterator |
---|
Source
Returns | The number of elements in this collection, if it can be cheaply computed, -1 otherwise. Cheaply usually means: Not requiring a collection traversal. |
---|---|
Inherited from | IterableOnce |
Source@inline
Inherited from | Iterator |
---|
Source
Inherited from | Iterator |
---|
Source
Finds the largest element.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the largest element of this collection with respect to the ordering |
Throws |
|
Inherited from | IterableOnceOps |
Source
Finds the first element which yields the largest value measured by function f.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the first element of this collection with the largest value measured by function f with respect to the ordering |
Throws |
|
Inherited from | IterableOnceOps |
Source
Finds the first element which yields the largest value measured by function f.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | an option value containing the first element of this collection with the largest value measured by function f with respect to the ordering |
Inherited from | IterableOnceOps |
Source
Finds the largest element.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | an option value containing the largest element of this collection with respect to the ordering |
Inherited from | IterableOnceOps |
Source
Finds the smallest element.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the smallest element of this collection with respect to the ordering |
Throws |
|
Inherited from | IterableOnceOps |
Source
Finds the first element which yields the smallest value measured by function f.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the first element of this collection with the smallest value measured by function f with respect to the ordering |
Throws |
|
Inherited from | IterableOnceOps |
Source
Finds the first element which yields the smallest value measured by function f.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | an option value containing the first element of this collection with the smallest value measured by function f with respect to the ordering |
Inherited from | IterableOnceOps |
Source
Finds the smallest element.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | an option value containing the smallest element of this collection with respect to the ordering |
Inherited from | IterableOnceOps |
Source@inline
Displays all elements of this collection in a string.
Delegates to addString, which can be overridden.
Returns | a string representation of this collection. In the resulting string the string representations (w.r.t. the method |
---|---|
Inherited from | IterableOnceOps |
Source@inline
Displays all elements of this collection in a string using a separator string.
Delegates to addString, which can be overridden.
Value parameters |
|
---|---|
Returns | a string representation of this collection. In the resulting string the string representations (w.r.t. the method |
Example |
|
Inherited from | IterableOnceOps |
Source
Displays all elements of this collection in a string using start, end, and separator strings.
Delegates to addString, which can be overridden.
Value parameters |
|
---|---|
Returns | a string representation of this collection. The resulting string begins with the string |
Example |
|
Inherited from | IterableOnceOps |
Source@throws(scala.throws.$lessinit$greater$default$1[scala.NoSuchElementException])
def
next(): A
Return the next element and advance the iterator.
Returns | the next element. |
---|---|
Throws |
|
Note | Reuse: Advances the iterator, which may exhaust the elements. It is valid to make additional calls on the iterator. |
Inherited from | Iterator |
Source
def
nextOption():
Option[A]
Wraps the value of next()
in an option.
Returns |
|
---|---|
Inherited from | Iterator |
Source@deprecatedOverriding("nonEmpty is defined as !isEmpty; override isEmpty instead", "2.13.0")
Tests whether the collection is not empty.
Returns |
|
---|---|
Inherited from | IterableOnceOps |
Source
A copy of this iterator with an element value appended until a given target length is reached.
Type parameters |
|
---|---|
Value parameters |
|
Returns | a new iterator consisting of all elements of this iterator followed by the minimal number of occurrences of |
Inherited from | Iterator |
Source
Partitions this iterator in two iterators according to a predicate.
Value parameters |
|
---|---|
Returns | a pair of iterators: the iterator that satisfies the predicate |
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. |
Inherited from | Iterator |
Source
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.
Value parameters |
|
---|---|
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. |
Inherited from | Iterator |
Source
Multiplies up the elements of this collection.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the product of all elements of this collection with respect to the |
Inherited from | IterableOnceOps |
Source
def
reduce[B >: A](op: (B, B) => B): B
Reduces the elements of this collection using the specified associative binary operator.
The order in which operations are performed on elements is unspecified and may be nondeterministic.
Type parameters |
|
---|---|
Value parameters |
|
Returns | The result of applying reduce operator |
Throws |
|
Inherited from | IterableOnceOps |
Source
def
reduceLeft[B >: A](op: (B, A) => B): B
Applies a binary operator to all elements of this collection, 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.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the result of inserting |
Throws |
|
Inherited from | IterableOnceOps |
Source
def
reduceLeftOption[B >: A](op: (B, A) => B):
Option[B]
Optionally applies a binary operator to all elements of this collection, 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.
Type parameters |
|
---|---|
Value parameters |
|
Returns | an option value containing the result of |
Inherited from | IterableOnceOps |
Source
def
reduceOption[B >: A](op: (B, B) => B):
Option[B]
Reduces the elements of this collection, if any, using the specified associative binary operator.
The order in which operations are performed on elements is unspecified and may be nondeterministic.
Type parameters |
|
---|---|
Value parameters |
|
Returns | An option value containing result of applying reduce operator |
Inherited from | IterableOnceOps |
Source
def
reduceRight[B >: A](op: (A, B) => B): B
Applies a binary operator to all elements of this collection, 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.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the result of inserting |
Throws |
|
Inherited from | IterableOnceOps |
Source
def
reduceRightOption[B >: A](op: (A, B) => B):
Option[B]
Optionally applies a binary operator to all elements of this collection, 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.
Type parameters |
|
---|---|
Value parameters |
|
Returns | an option value containing the result of |
Inherited from | IterableOnceOps |
Source
Inherited from | IterableOnceOps |
---|
Source
Checks whether corresponding elements of the given iterable collection compare equal (with respect to ==
) to elements of this iterator.
Type parameters |
|
---|---|
Value parameters |
|
Returns |
|
Inherited from | Iterator |
Source
Inherited from | Iterator |
---|
Source
The size of this collection.
Note: will not terminate for infinite-sized collections.
Returns | the number of elements in this collection. |
---|---|
Inherited from | IterableOnceOps |
Source
Inherited from | Iterator |
---|
Source
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 returned GroupedIterator
can be configured to either pad a partial result to size size
or suppress the partial result entirely.
Example usages:
// Returns List(ArraySeq(1, 2, 3), ArraySeq(2, 3, 4), ArraySeq(3, 4, 5)) (1 to 5).iterator.sliding(3).toList // Returns List(ArraySeq(1, 2, 3, 4), ArraySeq(4, 5)) (1 to 5).iterator.sliding(4, 3).toList // Returns List(ArraySeq(1, 2, 3, 4)) (1 to 5).iterator.sliding(4, 3).withPartial(false).toList // Returns List(ArraySeq(1, 2, 3, 4), ArraySeq(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
Value parameters |
|
---|---|
Returns | A |
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. |
Inherited from | Iterator |
Source
Splits this iterator into a prefix/suffix pair according to a predicate.
Note: c span p
is equivalent to (but possibly more efficient than) (c takeWhile p, c dropWhile p)
, provided the evaluation of the predicate p
does not cause any side-effects.
Note: might return different results for different runs, unless the underlying collection type is ordered.
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. |
---|---|
Inherited from | Iterator |
Source
Splits this collection into a prefix/suffix pair at a given position.
Note: c splitAt n
is equivalent to (but possibly more efficient than) (c take n, c drop n)
.
Note: might return different results for different runs, unless the underlying collection type is ordered.
Value parameters |
|
---|---|
Returns | a pair of collections consisting of the first |
Inherited from | IterableOnceOps |
Source
Returns a scala.collection.Stepper for the elements of this collection.
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 scala.collection.StepperShape parameter defines the resulting Stepper type according to the element type of this collection.
For collections of
Int
,Short
,Byte
orChar
, an scala.collection.IntStepper is returnedFor collections of
Double
orFloat
, a scala.collection.DoubleStepper is returnedFor collections of
Long
a scala.collection.LongStepper is returnedFor any other element type, an scala.collection.AnyStepper is returned
Note that this method is overridden in subclasses and the return type is refined to S with EfficientSplit
, for example scala.collection.IndexedSeqOps.stepper. For Steppers marked with scala.collection.Stepper.EfficientSplit, the converters in scala.jdk.StreamConverters allow creating parallel streams, whereas bare Steppers can be converted only to sequential streams.
Inherited from | IterableOnce |
---|
Source
Sums up the elements of this collection.
Note: will not terminate for infinite-sized collections.
Type parameters |
|
---|---|
Value parameters |
|
Returns | the sum of all elements of this collection with respect to the |
Inherited from | IterableOnceOps |
Source
Inherited from | Iterator |
---|
Source
Inherited from | Iterator |
---|
Source
Definition Classes | Iterator -> IterableOnceOps |
---|---|
Inherited from | Iterator |
Source
Given a collection factory factory
, convert this collection to the appropriate representation for the current element type A
. Example uses:
xs.to(List) xs.to(ArrayBuffer) xs.to(BitSet) // for xs: Iterable[Int]
Inherited from | IterableOnceOps |
---|
Source
Convert collection to array.
Implementation note: DO NOT call Array.from from this method.
Inherited from | IterableOnceOps |
---|
Source@inline
Inherited from | IterableOnceOps |
---|
Source
def
toIndexedSeq:
IndexedSeq[A]
Inherited from | IterableOnceOps |
---|
Source
Inherited from | IterableOnceOps |
---|
Source
Inherited from | IterableOnceOps |
---|
Source
Returns | This collection as a |
---|---|
Inherited from | IterableOnceOps |
Source
Inherited from | IterableOnceOps |
---|
Source
Converts this iterator to a string.
Returns |
|
---|---|
Note | Reuse: The iterator remains valid for further use whatever result is returned. |
Definition Classes | Iterator -> Any |
Inherited from | Iterator |
Source
Inherited from | IterableOnceOps |
---|
Source
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.
Value parameters |
|
---|---|
Returns | an iterator which produces those values of this iterator which satisfy the predicate |
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. |
Inherited from | Iterator |
Source
Inherited from | Iterator |
---|
Source
Inherited from | Iterator |
---|
Source
Inherited from | Iterator |
---|
© 2002-2022 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://scala-lang.org/api/3.1.1/scala/collection/AbstractIterator.html