Package org.cactoos.scalar
Class Or
- java.lang.Object
-
- org.cactoos.scalar.Or
-
public final class Or extends Object implements Scalar<Boolean>
Logical disjunction. This class performs short-circuit evaluation in which arguments are executed only if the preceding argument does not suffice to determine the value of the expression.This class can be effectively used to iterate through a collection, just like
Stream.forEach(java.util.function.Consumer)
works:new Or( new ProcOf<>(input -> System.out.printf("\'%s\' ", input) ), new IterableOf<>("Mary", "John", "William", "Napkin") ).value(); // will print 'Mary' 'John' 'William' 'Napkin' to standard output // the result of this operation is always false
This class could be also used for matching multiple boolean expressions:
new Or( new False(), new True(), new True() ).value(); // the result is true new Or( new False(), new False(), new False() ).value(); // the result is false
There is no thread-safety guarantee.
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.- Since:
- 0.8
-
-
Constructor Summary
Constructors Constructor Description Or(Iterable<? extends Scalar<Boolean>> iterable)
Ctor.Or(Func<? super X,Boolean> func, Iterable<? extends X> src)
Ctor.Or(Func<? super X,Boolean> func, X... src)
Ctor.Or(Proc<? super X> proc, Iterable<? extends X> src)
Ctor.Or(Proc<? super X> proc, X... src)
Ctor.Or(Scalar<Boolean>... scalar)
Ctor.Or(X subject, Func<? super X,Boolean>... conditions)
Ctor.
-
-
-
Constructor Detail
-
Or
@SafeVarargs public Or(Proc<? super X> proc, X... src)
Ctor.- Type Parameters:
X
- Type of items in the iterable- Parameters:
proc
- Proc to mapsrc
- The iterable
-
Or
@SafeVarargs public Or(Func<? super X,Boolean> func, X... src)
Ctor.- Type Parameters:
X
- Type of items in the iterable- Parameters:
func
- Func to mapsrc
- The iterable
-
Or
public Or(Proc<? super X> 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
-
Or
public Or(Func<? super X,Boolean> func, Iterable<? extends X> src)
Ctor.- Type Parameters:
X
- Type of items in the iterable- Parameters:
func
- Func to mapsrc
- The iterable
-
Or
@SafeVarargs public Or(X subject, Func<? super X,Boolean>... conditions)
Ctor.- Type Parameters:
X
- Type of items in the iterable- Parameters:
subject
- The subjectconditions
- Funcs to map
-
Or
@SafeVarargs public Or(Scalar<Boolean>... scalar)
Ctor.- Parameters:
scalar
- The Scalar.
-
-