Class Iterators

java.lang.Object
eu.bandm.tools.ops.Iterators

public final class Iterators extends Object
Library of combinators for classes implementing Iterator.
  • Method Details

    • cast

      public static <A> Iterator<A> cast(Iterator<? extends A> iterator)
      Forgets a wildcard in the element type of a given iterator.
      Parameters:
      iterator - an iterator
      Returns:
      the same iterator
    • empty

      public static <E> Iterator<E> empty()
      Returns an iterator consisting of no elements.
      Type Parameters:
      E - the type of elements returned by the returned iterator
      Returns:
      an iterator that has no elements
    • singleton

      public static <E> Iterator<E> singleton(E value)
      Returns an iterator consisting of exactly one given element. The element is not removable.
      Type Parameters:
      E - the type of elements returned by the returned iterator
      Parameters:
      value - the single element of the returned iterator
      Returns:
      an iterator that has exactly the given element
    • of

      @SafeVarargs public static <E> Iterator<E> of(E... things)
      Returns an iterator consisting of exactly the given elements. Elements are not removable.
      Type Parameters:
      E - the type of elements returned by the returned iterator
      Parameters:
      things - the elements of the returned iterator
      Returns:
      an iterator that has exactly the given elements
    • cons

      public static <E> Iterator<E> cons(E first, Iterator<E> rest)
      Returns an iterator consisting of the given first element preceding the remaining elements of a given iterator. The first element is not removable. Further removal requests are passed through to the underlying iterator.
      Type Parameters:
      E - the type of elements returned by the returned iterator
      Parameters:
      first - the first element
      rest - the iterator of the succeeding elements
      Returns:
      an iterator that returns the first element followed by the remaining elements of rest
      Throws:
      NullPointerException - if rest == null
    • concat

      public static <E> Iterator<E> concat(Iterator<? extends E> first, Iterator<? extends E> second)
      Returns an iterator consisting of the combined elements of two given iterators in order. Removal requests are passed through to the underlying iterators.
      Type Parameters:
      E - the type of elements returned by the returned iterator
      Parameters:
      first - the first iterator to consult for elements
      second - the second iterator to consult for elements
      Returns:
      an iterator that returns all remaining elements of first, followed by all remaining elements of second
      Throws:
      NullPointerException - if first == null or second == null
    • flatten

      public static <E> Iterator<E> flatten(Iterator<? extends Iterator<? extends E>> iterators)
      Returns an iterator consisting of the combined elements of all iterators returned by a given iterator in order. Removal requests are passed through to the underlying iterators.
      Type Parameters:
      E - the type of elements returned by the returned iterator
      Parameters:
      iterators - the iterators to be combined
      Returns:
      the combined interator
      Throws:
      NullPointerException - if iterators == null or one in the list is ==null.
    • bind

      @Undocumented public static <E, F> Iterator<F> bind(Function<? super E,? extends Iterator<? extends F>> fun, Iterator<E> things)
    • filter

      public static <E> Iterator<E> filter(Predicate<? super E> pred, Iterator<E> i)
      Returns an iterator consisting of the remaining elements of a given iterator that match the given predicate. Removal requests are passed through to the underlying iterator.
    • map

      public static <A, B> Iterator<B> map(Function<? super A,? extends B> fun, Iterator<A> it)
      Returns an iterator consisting of the results of applying the given function to the remaining elements of a given iterator. Removal requests are passed through to the underlying iterator.
    • comprehend

      @Deprecated(since="0.0") public static <A, B> Iterator<B> comprehend(Iterator<A> gen, Predicate<? super A> filter, Function<? super A,? extends B> map)
      Deprecated.
      ??? SONAR-BT
    • comprehend

      @Deprecated(since="0.0") public static <A, B> Iterator<B> comprehend(Iterator<A> gen, Function<? super A,? extends Iterator<B>> fun)
      Deprecated.
      ??? SONAR-BT
    • unmodifiableIterator

      @Undocumented public static <A> Iterator<A> unmodifiableIterator(Iterator<A> i)
    • lookahead

      @Undocumented public static <A> Iterators.LookaheadIterator<A> lookahead(Iterator<? extends A> things)
    • merge

      @Undocumented public static <A> Iterator<A> merge(Comparator<? super A> order, boolean removeDuplicates, Iterator<? extends A> left, Iterator<? extends A> right)
    • filterWithConstraint

      @Undocumented public static <A, B> Iterator<A> filterWithConstraint(BiPredicate<? super A,? super B> rel, Iterator<A> things, Iterator<B> constraints)
    • cacheHasNext

      @Undocumented public static <A> Iterator<A> cacheHasNext(Iterator<A> i)
    • drop

      @Undocumented public static <A> Iterator<A> drop(int n, Iterator<A> things)
    • take

      @Undocumented public static <A> Iterator<A> take(int n, Iterator<A> things)
    • elementwise

      @Undocumented public static <A> void elementwise(Consumer<? super A> sink, Iterator<A> it)