Class Filtered<X>

  • Type Parameters:
    X - Type of item
    All Implemented Interfaces:
    Iterator<X>

    public final class Filtered<X>
    extends Object
    implements Iterator<X>
    Filtered iterator.

    You can use it in order to create a declarative/lazy version of a filtered collection/iterable. For example, this code will create a list of two strings "hello" and "world":

     Iterator<String> list = new Filtered<>(
       new ArrayOf<>(
         "hey", "hello", "world"
       ).iterator(),
       input -> input.length() > 4
     );
     

    There is no thread-safety guarantee.

    Since:
    0.1
    See Also:
    Filtered
    • Constructor Detail

      • Filtered

        public Filtered​(Func<? super X,​Boolean> fnc,
                        Iterator<? extends X> src)
        Ctor.
        Parameters:
        fnc - Predicate
        src - Source iterable
      • Filtered

        public Filtered​(Iterator<? extends X> src,
                        Func<? super X,​Scalar<Boolean>> fnc)
        Ctor.
        Parameters:
        src - Source iterable
        fnc - Predicate
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface Iterator<X>
      • next

        public X next()
        Specified by:
        next in interface Iterator<X>
      • remove

        public void remove()
        Specified by:
        remove in interface Iterator<X>