public final class AndWithIndex extends Object implements Scalar<Boolean>
This class can be effectively used to iterate through
a collection, just like
Stream.forEach(java.util.function.Consumer)
works, but with an index provided for each item:
new UncheckedScalar<>(
new AndWithIndex(
new IterableOf<>("Mary", "John", "William", "Napkin"),
new BiFuncOf<>((text, index) ->
System.out.printf("| idx #%d: name: %s ", index, text), true)
)
).value();
// will print "| idx #0: name: Mary | idx #1: name: John |
// idx #2: name: William | idx #3: name: Napkin " to console
This class implements Scalar
, which throws a checked
Exception
. This may not be convenient in many cases. To make
it more convenient and get rid of the checked exception you can
use the UncheckedScalar
decorator. Or you may use
IoCheckedScalar
to wrap it in an IOException.
There is no thread-safety guarantee.
Constructor and Description |
---|
AndWithIndex(BiFunc<X,Integer,Boolean> func,
Iterable<X> src)
Ctor.
|
AndWithIndex(BiFunc<X,Integer,Boolean> func,
X... src)
Ctor.
|
AndWithIndex(BiProc<X,Integer> proc,
Iterable<X> src)
Ctor.
|
AndWithIndex(Func<Integer,Boolean>... src)
Ctor.
|
AndWithIndex(Iterable<Func<Integer,Boolean>> src)
Ctor.
|
AndWithIndex(Iterator<Func<Integer,Boolean>> src)
Ctor.
|
AndWithIndex(Proc<X> proc,
X... src)
Ctor.
|
@SafeVarargs public AndWithIndex(Proc<X> proc, X... src)
X
- Type of items in the iterableproc
- Proc to mapsrc
- The iterable@SafeVarargs public AndWithIndex(BiFunc<X,Integer,Boolean> func, X... src)
X
- Type of items in the iterablefunc
- Func to mapsrc
- The iterablepublic AndWithIndex(BiProc<X,Integer> proc, Iterable<X> src)
X
- Type of items in the iterablesrc
- The iterableproc
- Proc to usepublic AndWithIndex(BiFunc<X,Integer,Boolean> func, Iterable<X> src)
X
- Type of items in the iterablesrc
- The iterablefunc
- Func to map@SafeVarargs public AndWithIndex(Func<Integer,Boolean>... src)
src
- The iterablepublic AndWithIndex(Iterator<Func<Integer,Boolean>> src)
src
- The iteratorCopyright © 2017–2019 Cactoos. All rights reserved.