Class Iterators

java.lang.Object
me.sbasalaev.collection.Iterators

public final class Iterators extends Object
Factory methods for iterators. All iterators produced by this class are read only and do not support remove().
  • Method Details

    • empty

      public static <T> Iterator<T> empty()
      Empty iterator.
    • of

      @SafeVarargs public static <T> Iterator<T> of(T... elements)
      Iterator over given elements in given order.
    • ofRange

      public static <T> Iterator<T> ofRange(T[] elements, int offset, int size)
      Iterator over range of given array.
      Since:
      3.2
    • counting

      public static Iterator<Integer> counting(int start)
      Infinite iterator counting integers starting from given one.
    • wrapped

      public static <T> Iterator<Opt<T>> wrapped(Iterator<@Nullable T> iterator)
      Wraps elements produced by given iterator into Opt values.
      Since:
      3.2
    • filter

      public static <T> Iterator<T> filter(Iterator<T> iterator, Predicate<? super T> condition)
      Filters out iterator elements that do not satisfy condition.
    • map

      public static <T, R> Iterator<R> map(Iterator<T> iterator, Function<? super T,? extends R> mapping)
      Applies mapping to all elements of iterator.
    • chain

      public static <T> Iterator<T> chain(Iterator<? extends T> first, Iterator<? extends T> second)
      Concatenates two iterators together. The result first yields elements of the first iterator, and once it is exhausted, elements of the second.
    • zipBy

      public static <T, U, R> Iterator<R> zipBy(Iterator<T> first, Iterator<U> second, BiFunction<? super T,? super U,? extends R> combiner)
      Combines values produced by iterators using combiner.
    • limit

      public static <T> Iterator<T> limit(Iterator<T> iterator, int cap)
      Limits number of elements produced by iterator by cap.
    • takeWhile

      public static <T> Iterator<T> takeWhile(Iterator<T> iterator, Predicate<? super T> condition)
      Takes values from iterator until given condition fails.