Class IteratorSequence<T>

Type Parameters:
T - the type of the elements in the iterator

public class IteratorSequence<T> extends ForwardOnlySequence<T>
A sequence that loops over an iterator and can only go forward.
  • Constructor Details

    • IteratorSequence

      public IteratorSequence(Iterator<T> iterator)
      Creates a new sequence for the given iterator.
      Parameters:
      iterator - the iterator to loop over
  • Method Details

    • loop

      public <R> R loop(BiConsumer<Integer,T> consumer)
      Executes the given consumer for each element in the loop.

      If the iterator provided to the constructor was null, this method will do nothing.

      Specified by:
      loop in class ForwardOnlySequence<T>
      Type Parameters:
      R - the type of the return value
      Parameters:
      consumer - the consumer to execute for each element
      Returns:
      the value passed to Loop._break_(Object...), or null if the loop completes without a _break_