Package org.cactoos.scalar
Class Reduced<T>
- java.lang.Object
-
- org.cactoos.scalar.Reduced<T>
-
- Type Parameters:
T
- Scalar type
- All Implemented Interfaces:
Scalar<T>
public final class Reduced<T> extends Object implements Scalar<T>
Reduces iterable via BiFunc.new Reduced<>( (first, last) -> first + last, new IterableOf<>(() -> 1L, () -> 2L, () -> 3L, () -> 4L) ).value() // returns 10L
Here is how you can use it to find one of items according to the specified
BiFunc
:final String apple = new Reduced<>( (first, last) -> first, new IterableOf<Scalar<String>>( () -> "Apple", () -> "Banana", () -> "Orange" ) ).value(); final String orange = new Reduced<>( (first, last) -> last, new IterableOf<Scalar<String>>( () -> "Apple", () -> "Banana", () -> "Orange" ) ).value();
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.30
-
-
Constructor Summary
Constructors Constructor Description Reduced(Iterable<T> values, BiFunc<? super T,? super T,? extends T> reduce)
Ctor.Reduced(BiFunc<? super T,? super T,? extends T> reduce, Iterable<? extends Scalar<? extends T>> scalars)
Ctor.Reduced(BiFunc<? super T,? super T,? extends T> reduce, T... values)
Ctor.
-
-
-
Constructor Detail
-
Reduced
@SafeVarargs public Reduced(BiFunc<? super T,? super T,? extends T> reduce, T... values)
Ctor.- Parameters:
reduce
- Reducing functionvalues
- Values to be wrapped as scalars
-
Reduced
public Reduced(Iterable<T> values, BiFunc<? super T,? super T,? extends T> reduce)
Ctor.- Parameters:
values
- Values to be wrapped as scalarsreduce
- Reducing function- Since:
- 0.55.0
-
-