X
- The type to iterate overpublic final class ForEachWithIndex<X> extends Object implements Proc<Iterable<X>>
BiProc
for each element of an
Iterable
This class can be effectively used to iterate through a collection similar to how
Stream.forEach(java.util.function.Consumer)
works except
this class also passes the index of the current element to the proc:
new ForEachWithIndex(
new BiProcOf<>((input, index) -> System.out.printf("%d: \'%s\' ", index + 1, input)),
).execute(
new IterableOf<>("Mary", "John", "William", "Napkin")
); // will print 1: 'Mary' 2: 'John' 3: 'William' 4: 'Napkin' to standard output
There is no thread-safety guarantee.
Constructor and Description |
---|
ForEachWithIndex(BiProc<X,Integer> proc)
Ctor.
|
Copyright © 2017–2021 Cactoos. All rights reserved.