base class Iterator<+T>
A stateful instance describing one iteration pass over a sequence of values. Calling next() advances the iterator and returns Some(item) if there are more items or None() when there are no more items. An iterator cannot be reset: mutable methods will, in general, advance the iterator.
Methods
Returns a hint of the number of items that this Iterator may yield:
- Returns Some(n) if the exact number of items is known. Examples: iterators over concrete collections, 1:1 transform operations (e.g. map()).
- Otherwise returns None(). Examples: transform operations that may not be 1:1, such as filter(), flatMap(), takeWhile(), etc.
Advance the Iterator's position and return Some() with the next item, or None() if there are no more items.
Collects the results of this sequence into an instance of the given class.
Iteration
mutable fun sourceeach(f: (T) -> Void): VoidMethods for iterating over the items of an iterator for the purpose of executing side effects. Calls the given function once per element of this iterator.
Composition
mutable fun sourcemap<U>(f: (T) -> U): mutable Iterator<U>Methods for creating a new iterator that represents the results of applying an operation to the items of this iterator. In general the operation is applied lazily, when the returned iterator is advanced, but implementations may modify the original iterator in place. Callers should not use the source iterator (this) after applying a composition operator. Returns a new iterator representing the results of calling the selection function on each element of this iterator.
Returns a new iterator representing the results of calling the selection function on each element to map each element to an iterator, and (conceptually) flattening the resulting iterators.
Returns a new iterator representing all the elements of this iterator for which the predicate returns true.
Returns a new iterator representing tuples of the ith elements of this and the other iterator.
Returns a new iterator representing the results of calling the selection function with tuples of the ith elements of this and the other iterator.
Returns a new iterator representing the elements of this iterator after the nth element.
Returns a new iterator representing the elements of this iterator after the contiguous prefix for which the predicate returns true.
Returns a new iterator representing the first n elements of this.
Returns a new iterator representing the contiguous prefix of elements from this for which the predicate returns true.
Aggregation
mutable fun sourcefind(p: (T) -> Bool): Option<T>Methods that aggregate (or "reduce") the items of an iterator into a single value. Returns Some(x) for the first item in this iterator that matches the predicate, or None() if no items match.
Returns true if the predicate returns true for all elements of this iterator.
Returns true if the predicate returns true for at least one element of this iterator.
Returns the result of applying an accumulator function to all the elements of this iterator.
Returns an iterator that yields tuples of (index, item), where index is the zero-based index of the item within the stream of values yielded by this iterator.
Extensions
mutable fun sourceeachWithIndex(f: (Int, T) -> Void): VoidTODO: move to extension classes when .ModuleClass can be extended Calls the given function with the index and value for each item in this iterator. The index is the zero-based index of the value within the sequence of values provided: for iterators over a concrete, indexed collection the index does not necessarily correspond to the index of the value in the original collection.