T
- Component type of this foldablepublic interface Foldable<T>
Monoid
s.
Example:
Monoid<String> concat = Monoid.of("", (a1, a2) -> a1 + a2);
Stream.of("1", "2", "3").fold(concat);
is the same as
Stream.of("1", "2", "3").fold("", (a1, a2) -> a1 + a2);
Modifier and Type | Method and Description |
---|---|
default T |
fold(Monoid<? extends T> monoid)
Folds this elements from the left, starting with
monoid.zero() and successively calling monoid::combine . |
default T |
fold(T zero,
java.util.function.BiFunction<? super T,? super T,? extends T> combine)
Folds this elements from the left, starting with
zero and successively calling combine . |
default T |
foldLeft(Monoid<? extends T> monoid)
Folds this elements from the left, starting with
monoid.zero() and successively calling monoid::combine . |
<U> U |
foldLeft(U zero,
java.util.function.BiFunction<? super U,? super T,? extends U> combine)
Folds this elements from the left, starting with
zero and successively calling combine . |
default <U> U |
foldMap(Monoid<U> monoid,
java.util.function.Function<? super T,? extends U> mapper)
Maps this elements to a
Monoid and applies foldLeft , starting with monoid.zero() : |
default T |
foldRight(Monoid<? extends T> monoid)
Folds this elements from the right, starting with
monoid.zero() and successively calling monoid::combine . |
<U> U |
foldRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> combine)
Folds this elements from the right, starting with
zero and successively calling combine . |
default T fold(Monoid<? extends T> monoid)
monoid.zero()
and successively calling monoid::combine
.monoid
- A monoid, providing a zero
and a combine
function.NullPointerException
- if monoid
is nulldefault T fold(T zero, java.util.function.BiFunction<? super T,? super T,? extends T> combine)
zero
and successively calling combine
.zero
- A zero element to start with.combine
- A function which combines elements.NullPointerException
- if combine
is nulldefault T foldLeft(Monoid<? extends T> monoid)
monoid.zero()
and successively calling monoid::combine
.monoid
- A monoid, providing a zero
and a combine
function.NullPointerException
- if monoid
is null<U> U foldLeft(U zero, java.util.function.BiFunction<? super U,? super T,? extends U> combine)
zero
and successively calling combine
.U
- the type of the folded valuezero
- A zero element to start with.combine
- A function which combines elements.NullPointerException
- if combine
is nulldefault <U> U foldMap(Monoid<U> monoid, java.util.function.Function<? super T,? extends U> mapper)
Monoid
and applies foldLeft
, starting with monoid.zero()
:
foldLeft(monoid.zero(), (ys, x) -> monoid.combine(ys, mapper.apply(x)));
U
- Component type of the given monoid.monoid
- A Monoidmapper
- A mapperNullPointerException
- if monoid
or mapper
is nulldefault T foldRight(Monoid<? extends T> monoid)
monoid.zero()
and successively calling monoid::combine
.monoid
- A monoid, providing a zero
and a combine
function.NullPointerException
- if monoid
is null<U> U foldRight(U zero, java.util.function.BiFunction<? super T,? super U,? extends U> combine)
zero
and successively calling combine
.U
- the type of the folded valuezero
- A zero element to start with.combine
- A function which combines elements.NullPointerException
- if combine
is nullCopyright © 2015. All Rights Reserved.