T - Component type of this foldable@Deprecated
public interface Foldable<T>
Example:
// = "123"
Stream.of("1", "2", "3").fold("", (a1, a2) -> a1 + a2);
| Modifier and Type | Method and Description |
|---|---|
default T |
fold(T zero,
java.util.function.BiFunction<? super T,? super T,? extends T> combine)
Deprecated.
Folds this elements using the given associative binary operator, starting with
zero and
successively calling combine. |
<U> U |
foldLeft(U zero,
java.util.function.BiFunction<? super U,? super T,? extends U> combine)
Deprecated.
Folds this elements from the left, starting with
zero and successively calling combine. |
<U> U |
foldRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> combine)
Deprecated.
Folds this elements from the right, starting with
zero and successively calling combine. |
default T |
reduce(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.
Accumulates the elements of this Foldable by successively calling the given operation
op. |
T |
reduceLeft(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.
Accumulates the elements of this Foldable by successively calling the given operation
op from the left. |
Option<T> |
reduceLeftOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.
Accumulates the elements of this Foldable by successively calling the given operation
op from the left. |
default Option<T> |
reduceOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.
Accumulates the elements of this Foldable by successively calling the given operation
op. |
T |
reduceRight(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.
Accumulates the elements of this Foldable by successively calling the given operation
op from the right. |
Option<T> |
reduceRightOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.
Accumulates the elements of this Foldable by successively calling the given operation
op from the right. |
default T fold(T zero, java.util.function.BiFunction<? super T,? super T,? extends T> combine)
zero and
successively calling combine. The order in which the elements are combined is
non-deterministic.
The methods fold, foldLeft and foldRight differ in how the elements are combined:
foldLeft(Object, BiFunction) associates to the leftfoldRight(Object, BiFunction) associates to the rightfold takes an associative combine operation because the traversal of elements is
unordered/non-deterministic. The associativity guarantees that in each case the result will
be the same, it does not matter in which order the elements are combined. Generally binary
operators aren't associative, i.e. the result may differ if elements are combined in a different
order.
We say that this Foldable and the associative combine operation form a Monoid.
// = 6
Set(1, 2, 3).fold(0, (a, b) -> a + b);
zero - A zero element to start with.combine - A function which combines elements.java.lang.NullPointerException - if combine is null<U> U foldLeft(U zero,
java.util.function.BiFunction<? super U,? super T,? extends U> combine)
zero and successively calling combine.
Example:
// = "cba!"
List("a", "b", "c").foldLeft("!", (xs, x) -> x + xs)
U - the type to fold overzero - A zero element to start with.combine - A function which combines elements.java.lang.NullPointerException - if combine is null<U> U foldRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> combine)
zero and successively calling combine.
Example:
// = "!cba"
List("a", "b", "c").foldRight("!", (x, xs) -> xs + x)
U - the type of the folded valuezero - A zero element to start with.combine - A function which combines elements.java.lang.NullPointerException - if combine is nulldefault T reduce(java.util.function.BiFunction<? super T,? super T,? extends T> op)
op.
The order of element iteration is undetermined.op - A BiFunction of type Tjava.util.NoSuchElementException - if this is emptyjava.lang.NullPointerException - if op is nulldefault Option<T> reduceOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
op.
The order of element iteration is undetermined.op - A BiFunction of type Tjava.lang.NullPointerException - if op is nullT reduceLeft(java.util.function.BiFunction<? super T,? super T,? extends T> op)
op from the left.op - A BiFunction of type Tjava.util.NoSuchElementException - if this is emptyjava.lang.NullPointerException - if op is nullOption<T> reduceLeftOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
op from the left.op - A BiFunction of type Tjava.lang.NullPointerException - if op is nullT reduceRight(java.util.function.BiFunction<? super T,? super T,? extends T> op)
op from the right.op - An operation of type Tjava.util.NoSuchElementException - if this is emptyjava.lang.NullPointerException - if op is nullOption<T> reduceRightOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
op from the right.op - An operation of type Tjava.lang.NullPointerException - if op is null