Class ForwardOnlySequence<T>

java.lang.Object
ste.lloop.AbstractSequence<ForwardOnlySequence<T>, T>
ste.lloop.ForwardOnlySequence<T>
Type Parameters:
T - the type of the elements in the sequence
Direct Known Subclasses:
IterableSequence, IteratorSequence, LinesSequence

public abstract class ForwardOnlySequence<T> extends AbstractSequence<ForwardOnlySequence<T>, T>
A sequence that loops only forwards
  • Constructor Details

    • ForwardOnlySequence

      protected ForwardOnlySequence()
      Constructs a new ForwardOnlySequence instance.
  • Method Details

    • to

      public ForwardOnlySequence<T> to(int to)
      Description copied from class: AbstractSequence
      Sets the ending index of the loop (inclusive).
      Overrides:
      to in class AbstractSequence<ForwardOnlySequence<T>, T>
      Parameters:
      to - the ending index
      Returns:
      this instance
    • from

      public ForwardOnlySequence<T> from(int from)
      Description copied from class: AbstractSequence
      Sets the starting index of the loop (inclusive).
      Overrides:
      from in class AbstractSequence<ForwardOnlySequence<T>, T>
      Parameters:
      from - the starting index
      Returns:
      this instance
    • step

      public ForwardOnlySequence<T> step(int step)
      Description copied from class: AbstractSequence
      Sets the step of the loop. The sign of the step determines the direction of the loop.

      If the step is positive, the loop will go from from to to. If the step is negative, the loop will go from to to from.

      The absolute value of the step is used as the increment. If the step is zero, the loop will not execute.

      Overrides:
      step in class AbstractSequence<ForwardOnlySequence<T>, T>
      Parameters:
      step - the step value
      Returns:
      this instance
    • loop

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

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

      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_
    • loop

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

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

      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_