Class ForEach<X>

  • Type Parameters:
    X - The type to iterate over
    All Implemented Interfaces:
    Proc<Iterable<? extends X>>

    public final class ForEach<X>
    extends Object
    implements Proc<Iterable<? extends X>>
    Executes a Proc for each element of an Iterable

    This class can be effectively used to iterate through a collection, just like Stream.forEach(java.util.function.Consumer) works:

    new ForEach( new ProcOf<>(input -> System.out.printf("\'%s\' ", input)), ).execute( new IterableOf<>("Mary", "John", "William", "Napkin") ); // will print 'Mary' 'John' 'William' 'Napkin' to standard output

    There is no thread-safety guarantee.

    Since:
    1.0
    • Constructor Detail

      • ForEach

        public ForEach​(Proc<? super X> proc)
        Ctor.
        Parameters:
        proc - The proc to execute
    • Method Detail

      • exec

        public void exec​(Iterable<? extends X> input)
                  throws Exception
        Description copied from interface: Proc
        Execute it.
        Specified by:
        exec in interface Proc<X>
        Parameters:
        input - The argument
        Throws:
        Exception - If fails