T
- Scalar typepublic final class Reduced<T> extends Object implements Scalar<T>
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 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.
Copyright © 2017–2019 Cactoos. All rights reserved.