Package org.cactoos.scalar
Class AndWithIndex
- java.lang.Object
-
- org.cactoos.scalar.AndWithIndex
-
public final class AndWithIndex extends Object implements Scalar<Boolean>
Logical conjunction, with index.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 checkedException
. This may not be convenient in many cases. To make it more convenient and get rid of the checked exception you can use theUnchecked
decorator. Or you may useIoChecked
to wrap it in an IOException.There is no thread-safety guarantee.
- Since:
- 0.20
-
-
Constructor Summary
Constructors Constructor Description AndWithIndex(Iterable<? extends Func<Integer,Boolean>> src)
Ctor.AndWithIndex(BiFunc<? super X,Integer,Boolean> func, Iterable<? extends X> src)
Ctor.AndWithIndex(BiFunc<? super X,Integer,Boolean> func, X... src)
Ctor.AndWithIndex(BiProc<? super X,Integer> proc, Iterable<? extends X> src)
Ctor.AndWithIndex(Func<Integer,Boolean>... src)
Ctor.AndWithIndex(Proc<? super X> proc, X... src)
Ctor.
-
-
-
Constructor Detail
-
AndWithIndex
@SafeVarargs public AndWithIndex(Proc<? super X> proc, X... src)
Ctor.- Type Parameters:
X
- Type of items in the iterable- Parameters:
proc
- Proc to mapsrc
- The iterable
-
AndWithIndex
@SafeVarargs public AndWithIndex(BiFunc<? super X,Integer,Boolean> func, X... src)
Ctor.- Type Parameters:
X
- Type of items in the iterable- Parameters:
func
- Func to mapsrc
- The iterable
-
AndWithIndex
public AndWithIndex(BiProc<? super X,Integer> proc, Iterable<? extends X> src)
Ctor.- Type Parameters:
X
- Type of items in the iterable- Parameters:
proc
- Proc to usesrc
- The iterable- Since:
- 0.24
-
AndWithIndex
public AndWithIndex(BiFunc<? super X,Integer,Boolean> func, Iterable<? extends X> src)
Ctor.- Type Parameters:
X
- Type of items in the iterable- Parameters:
func
- Func to mapsrc
- The iterable- Since:
- 0.24
-
AndWithIndex
@SafeVarargs public AndWithIndex(Func<Integer,Boolean>... src)
Ctor.- Parameters:
src
- The iterable
-
-