public interface Foldable<T>
Modifier and Type | Method and Description |
---|---|
default T |
foldRight(Monoid<T> reducer)
ReactiveSeq.of("a","b","c").foldRight(Reducers.toString(""));
// "cab"
|
default T |
foldRight(T identity,
java.util.function.BinaryOperator<T> accumulator)
Immutable reduction from right to left
|
default <U> U |
foldRight(U identity,
java.util.function.BiFunction<? super T,U,U> accumulator) |
default <T> T |
foldRightMapToType(Reducer<T> reducer)
Attempt to map this Monad to the same type as the supplied Monoid (using
mapToType on the monoid interface) Then use Monoid to reduce values
|
default java.lang.String |
join()
assertEquals("123".length(),ReactiveSeq.of(1, 2, 3).join().length());
|
default java.lang.String |
join(java.lang.String sep)
assertEquals("1, 2, 3".length(), ReactiveSeq.of(1, 2, 3).join(", ").length());
|
default java.lang.String |
join(java.lang.String sep,
java.lang.String start,
java.lang.String end)
assertEquals("^1|2|3$".length(), of(1, 2, 3).join("|", "^", "$").length());
|
default <R> R |
mapReduce(java.util.function.Function<? super T,? extends R> mapper,
Monoid<R> reducer)
Attempt to map this Monad to the same type as the supplied Monoid, using
supplied function Then use Monoid to reduce values
|
default <R> R |
mapReduce(Reducer<R> reducer)
Attempt to map this Sequence to the same type as the supplied Monoid
(Reducer) Then use Monoid to reduce values
|
default void |
print(java.io.PrintStream str) |
default void |
print(java.io.PrintWriter writer) |
default void |
printErr() |
default void |
printOut() |
default java.util.Optional<T> |
reduce(java.util.function.BinaryOperator<T> accumulator) |
default ListX<T> |
reduce(java.lang.Iterable<? extends Monoid<T>> reducers)
Reduce with multiple reducers in parallel NB if this Monad is an Optional
[Arrays.asList(1,2,3)] reduce will operate on the Optional as if the list
was one value To reduce over the values on the list, called
streamedMonad() first.
|
default T |
reduce(Monoid<T> reducer)
ReactiveSeq.of("hello","2","world","4").reduce(Reducers.toString(","));
//hello,2,world,4
|
default ListX<T> |
reduce(java.util.stream.Stream<? extends Monoid<T>> reducers)
Reduce with multiple reducers in parallel NB if this Monad is an Optional
[Arrays.asList(1,2,3)] reduce will operate on the Optional as if the list
was one value To reduce over the values on the list, called
streamedMonad() first.
|
default T |
reduce(T identity,
java.util.function.BinaryOperator<T> accumulator) |
default <U> U |
reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator) |
default <U> U |
reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator,
java.util.function.BinaryOperator<U> combiner) |
ReactiveSeq<T> |
stream() |
ReactiveSeq<T> stream()
default <R> R mapReduce(Reducer<R> reducer)
ReactiveSeq.of("hello","2","world","4").mapReduce(Reducers.toCountInt());
//4
reducer
- Monoid to reduce valuesdefault <R> R mapReduce(java.util.function.Function<? super T,? extends R> mapper, Monoid<R> reducer)
ReactiveSeq.of("one","two","three","four")
.mapReduce(this::toInt,Reducers.toTotalInt());
//10
int toInt(String s){
if("one".equals(s))
return 1;
if("two".equals(s))
return 2;
if("three".equals(s))
return 3;
if("four".equals(s))
return 4;
return -1;
}
mapper
- Function to map Monad typereducer
- Monoid to reduce valuesdefault T reduce(Monoid<T> reducer)
ReactiveSeq.of("hello","2","world","4").reduce(Reducers.toString(","));
//hello,2,world,4
reducer
- Use supplied Monoid to reduce valuesdefault <U> U reduce(U identity, java.util.function.BiFunction<U,? super T,U> accumulator)
default <U> U reduce(U identity, java.util.function.BiFunction<U,? super T,U> accumulator, java.util.function.BinaryOperator<U> combiner)
default ListX<T> reduce(java.util.stream.Stream<? extends Monoid<T>> reducers)
{ @code Monoid<Integer> sum = Monoid.of(0, (a, b) -> a + b); Monoid<Integer> mult = Monoid.of(1, (a, b) -> a * b); List<Integer> result = ReactiveSeq.of(1, 2, 3, 4).reduce(Arrays.asList(sum, mult).stream()); assertThat(result, equalTo(Arrays.asList(10, 24))); }
reducers
- default ListX<T> reduce(java.lang.Iterable<? extends Monoid<T>> reducers)
Monoid<Integer> sum = Monoid.of(0,(a,b)->a+b);
Monoid<Integer> mult = Monoid.of(1,(a,b)->a*b);
List<Integer> result = ReactiveSeq.of(1,2,3,4))
.reduce(Arrays.asList(sum,mult) );
assertThat(result,equalTo(Arrays.asList(10,24)));
reducers
- default T foldRight(Monoid<T> reducer)
ReactiveSeq.of("a","b","c").foldRight(Reducers.toString(""));
// "cab"
reducer
- Use supplied Monoid to reduce values starting via foldRightdefault T foldRight(T identity, java.util.function.BinaryOperator<T> accumulator)
assertTrue(ReactiveSeq.of("a","b","c").foldRight("", String::concat).equals("cba"));
identity
- accumulator
- default <U> U foldRight(U identity, java.util.function.BiFunction<? super T,U,U> accumulator)
default <T> T foldRightMapToType(Reducer<T> reducer)
ReactiveSeq.of(1,2,3).foldRightMapToType(Reducers.toString(""));
// "321"
reducer
- Monoid to reduce valuesdefault java.lang.String join()
assertEquals("123".length(),ReactiveSeq.of(1, 2, 3).join().length());
default java.lang.String join(java.lang.String sep)
assertEquals("1, 2, 3".length(), ReactiveSeq.of(1, 2, 3).join(", ").length());
default java.lang.String join(java.lang.String sep, java.lang.String start, java.lang.String end)
assertEquals("^1|2|3$".length(), of(1, 2, 3).join("|", "^", "$").length());
default void print(java.io.PrintStream str)
default void print(java.io.PrintWriter writer)
default void printOut()
default void printErr()