Package org.cactoos.proc
Class ForEach<X>
- java.lang.Object
-
- org.cactoos.proc.ForEach<X>
-
- Type Parameters:
X
- The type to iterate over
public final class ForEach<X> extends Object implements Proc<Iterable<? extends X>>
Executes aProc
for each element of anIterable
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