Interface Pipeline<T>

  • Type Parameters:
    T - the type of elements contained in the original collection
    All Superinterfaces:
    Foldable<T>, java.lang.Iterable<T>, Streamable<T>

    public interface Pipeline<T>
    extends Foldable<T>, Streamable<T>
    A pipeline is a set of commands that will be applied on top any Collection. Each command is lazy and will only get executed once the pipe is terminated.

    Note that a pipeline can be split by re-using the intermediate operation. Each pipeline after the split will yield a different result and not modify the steps in between.

    Example:

    
        Pipeline<Integer> intermediatePipe = API.List(1, 2, 3, 4)
              .pipeline()
              .filter(x -> x % 2 == 0);
    
        Pipeline<String> stringPipe = intermediatePipe.map(String::valueOf);
        Pipeline<Integer> finalPipe = intermediatePipe.map(x -> x * x / 3);
    
     
    Since:
    1.0.6
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void consume​(java.util.function.Consumer<T> consumer)
      Consumes each element in the pipeline using the provided consume operation.
      Pipeline<T> filter​(java.util.function.Predicate<T> predicate)
      Filter out an element if it does not match the supplied predicate.
      java.util.Iterator<T> iterator()
      This will return the iterator for this pipelines elements.
      <U> Pipeline<U> map​(java.util.function.Function<T,​U> mapper)
      Perform a mapping operation on the elements in the stream.
      Pipeline<T> reject​(java.util.function.Predicate<T> predicate)
      Reject all values that match the provided predicate.
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Method Detail

      • consume

        void consume​(java.util.function.Consumer<T> consumer)
        Consumes each element in the pipeline using the provided consume operation. This is a terminal operation.
        Parameters:
        consumer - the consumer
        Throws:
        java.lang.NullPointerException - if the consumer is null
      • filter

        Pipeline<T> filter​(java.util.function.Predicate<T> predicate)
        Description copied from interface: Streamable
        Filter out an element if it does not match the supplied predicate. This operation will iterate over all elements and return a new set containing only the elements where the predicate returns true for.
        Specified by:
        filter in interface Streamable<T>
        Parameters:
        predicate - the predicate to apply to the contents of this
        Returns:
        the filtered value
      • iterator

        java.util.Iterator<T> iterator()
        This will return the iterator for this pipelines elements. This is a terminal operation.
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Returns:
        the iterator for all elements in the pipeline
      • map

        <U> Pipeline<U> map​(java.util.function.Function<T,​U> mapper)
        Description copied from interface: Streamable
        Perform a mapping operation on the elements in the stream.

        This operation will loop over all elements in the stream and apply the mapper method. The mapped values will be returned in as a new stream of elements.

        Specified by:
        map in interface Streamable<T>
        Type Parameters:
        U - the type of object expected as a result
        Parameters:
        mapper - the mapping functionality
        Returns:
        the mapped object
      • reject

        Pipeline<T> reject​(java.util.function.Predicate<T> predicate)
        Reject all values that match the provided predicate. This is the logical inverse of the operation filter(Predicate).
        Parameters:
        predicate - the predicate to use
        Returns:
        a pipeline instruction rejecting all values matching the predicate