Package ste.lloop

Class ForwardOnlySequence<T>

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

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

    • ForwardOnlySequence

      public ForwardOnlySequence(Iterable<T> iterable)
      Creates a new sequence for the given iterable.
      Parameters:
      iterable - the iterable to loop over
  • 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>>
      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>>
      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>>
      Parameters:
      step - the step value
      Returns:
      this instance
    • loop

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

      If the iterable 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.brk(Object), or null if the loop completes without a brk