public interface NestedFoldable<W extends WitnessType<W>,T> extends ToStream<T>
Modifier and Type | Method and Description |
---|---|
default AnyM<W,java.lang.Boolean> |
endsWith(java.util.stream.Stream<T> stream)
assertTrue(ReactiveSeq.of(1,2,3,4,5,6)
.endsWith(Stream.of(5,6)));
|
default AnyM<W,java.lang.Boolean> |
endsWithIterable(java.lang.Iterable<T> iterable)
assertTrue(ReactiveSeq.of(1,2,3,4,5,6)
.endsWith(Arrays.asList(5,6)));
|
default AnyM<W,java.util.Optional<T>> |
findFirst() |
default AnyM<W,T> |
firstValue()
assertThat(ReactiveSeq.of(1,2,3,4)
.map(u->{throw new RuntimeException();})
.recover(e->"hello")
.firstValue(),equalTo("hello"));
|
default AnyM<W,T> |
foldRight(Monoid<T> reducer)
ReactiveSeq.of("a","b","c").foldRight(Reducers.toString(""));
// "cab"
|
default AnyM<W,T> |
foldRight(T identity,
java.util.function.BinaryOperator<T> accumulator)
Immutable reduction from right to left
|
default <U> AnyM<W,U> |
foldRight(U identity,
java.util.function.BiFunction<? super T,U,U> accumulator)
Immutable reduction from right to left
|
default <T> AnyM<W,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 <X extends java.lang.Throwable> |
forEach(long numberOfElements,
java.util.function.Consumer<? super T> consumer,
java.util.function.Consumer<? super java.lang.Throwable> consumerError) |
default <X extends java.lang.Throwable> |
forEach(long numberOfElements,
java.util.function.Consumer<? super T> consumer,
java.util.function.Consumer<? super java.lang.Throwable> consumerError,
java.lang.Runnable onComplete) |
default AnyM<W,Maybe<T>> |
get(long index)
Return the elementAt index or Optional.zero
|
default <K> AnyM<W,MapX<K,ListX<T>>> |
groupBy(java.util.function.Function<? super T,? extends K> classifier)
Use classifier function to group elements in this Sequence into a Map
|
default AnyM<W,java.lang.String> |
join()
assertEquals("123".length(),ReactiveSeq.of(1, 2, 3).join().length());
|
default AnyM<W,java.lang.String> |
join(java.lang.String sep)
assertEquals("1, 2, 3".length(), ReactiveSeq.of(1, 2, 3).join(", ").length());
|
default AnyM<W,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> AnyM<W,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> AnyM<W,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
|
AnyM<W,? extends CyclopsCollectable<T>> |
nestedFoldables() |
default void |
print(java.io.PrintStream str) |
default void |
print(java.io.PrintWriter writer) |
default void |
printErr() |
default void |
printOut() |
default AnyM<W,java.util.Optional<T>> |
reduce(java.util.function.BinaryOperator<T> accumulator) |
default ListT<W,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 AnyM<W,T> |
reduce(Monoid<T> reducer)
ReactiveSeq.of("hello","2","world","4").reduce(Reducers.toString(","));
//hello,2,world,4
|
default ListT<W,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 AnyM<W,T> |
reduce(T identity,
java.util.function.BinaryOperator<T> accumulator) |
default <U> AnyM<W,U> |
reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator,
java.util.function.BinaryOperator<U> combiner) |
default HotStream<T> |
schedule(java.lang.String cron,
java.util.concurrent.ScheduledExecutorService ex)
Execute this Stream on a schedule
|
default HotStream<T> |
scheduleFixedDelay(long delay,
java.util.concurrent.ScheduledExecutorService ex)
Execute this Stream on a schedule
|
default HotStream<T> |
scheduleFixedRate(long rate,
java.util.concurrent.ScheduledExecutorService ex)
Execute this Stream on a schedule
|
default AnyM<W,Maybe<T>> |
single()
//Optional[1]
ReactiveSeq.of(1).singleUnsafe();
//Optional.zero
ReactiveSeq.of().singleOpional();
//Optional.zero
ReactiveSeq.of(1,2,3).singleUnsafe();
|
default AnyM<W,Maybe<T>> |
single(java.util.function.Predicate<? super T> predicate) |
default AnyM<W,T> |
singleUnsafe()
//1
ReactiveSeq.of(1).singleUnsafe();
//UnsupportedOperationException
ReactiveSeq.of().singleUnsafe();
//UnsupportedOperationException
ReactiveSeq.of(1,2,3).singleUnsafe();
|
default AnyM<W,java.lang.Boolean> |
startsWith(java.util.stream.Stream<T> stream)
assertTrue(ReactiveSeq.of(1,2,3,4).startsWith(Arrays.asList(1,2,3).iterator())) |
default AnyM<W,java.lang.Boolean> |
startsWithIterable(java.lang.Iterable<T> iterable)
assertTrue(ReactiveSeq.of(1,2,3,4).startsWith(Arrays.asList(1,2,3)));
|
default <R> AnyM<W,R> |
toNested(java.util.function.Function<? super ConvertableSequence<T>,? extends R> fn) |
futureStream, getStreamable, isEmpty, jdkStream, reactiveSeq, reveresedJDKStream, reveresedStream, stream
AnyM<W,? extends CyclopsCollectable<T>> nestedFoldables()
default <X extends java.lang.Throwable> AnyM<W,? extends org.reactivestreams.Subscription> forEach(long numberOfElements, java.util.function.Consumer<? super T> consumer, java.util.function.Consumer<? super java.lang.Throwable> consumerError)
default <X extends java.lang.Throwable> AnyM<W,? extends org.reactivestreams.Subscription> forEach(long numberOfElements, java.util.function.Consumer<? super T> consumer, java.util.function.Consumer<? super java.lang.Throwable> consumerError, java.lang.Runnable onComplete)
default <R> AnyM<W,R> mapReduce(Reducer<R> reducer)
ReactiveSeq.of("hello","2","world","4").mapReduce(Reducers.toCountInt());
//4
reducer
- Monoid to reduce valuesdefault <R> AnyM<W,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 AnyM<W,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 AnyM<W,java.util.Optional<T>> reduce(java.util.function.BinaryOperator<T> accumulator)
default <U> AnyM<W,U> reduce(U identity, java.util.function.BiFunction<U,? super T,U> accumulator, java.util.function.BinaryOperator<U> combiner)
default ListT<W,T> reduce(java.util.stream.Stream<? 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).transformerStream());
assertThat(result, equalTo(Arrays.asList(10, 24)));
reducers
- default ListT<W,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 AnyM<W,T> foldRight(Monoid<T> reducer)
ReactiveSeq.of("a","b","c").foldRight(Reducers.toString(""));
// "cab"
reducer
- Use supplied Monoid to reduce values starting via foldRightdefault AnyM<W,T> foldRight(T identity, java.util.function.BinaryOperator<T> accumulator)
assertTrue(ReactiveSeq.of("a","b","c").foldRight("", String::concat).equals("cba"));
identity
- value that results in the input parameter to the accumulator function being returned.
E.g. for multiplication 1 is the identity value, for addition 0 is the identity valueaccumulator
- function that combines the accumulated value and the next onedefault <U> AnyM<W,U> foldRight(U identity, java.util.function.BiFunction<? super T,U,U> accumulator)
assertTrue(ReactiveSeq.of("a","b","c").foldRight("", (a,b)->a+b).equals("cba"));
*identity
- value that results in the input parameter to the accumulator function being returned.
E.g. for multiplication 1 is the identity value, for addition 0 is the identity valueaccumulator
- function that combines the accumulated value and the next onedefault <T> AnyM<W,T> foldRightMapToType(Reducer<T> reducer)
ReactiveSeq.of(1,2,3).foldRightMapToType(Reducers.toString(""));
// "321"
reducer
- Monoid to reduce valuesdefault AnyM<W,java.lang.String> join()
assertEquals("123".length(),ReactiveSeq.of(1, 2, 3).join().length());
default AnyM<W,java.lang.String> join(java.lang.String sep)
assertEquals("1, 2, 3".length(), ReactiveSeq.of(1, 2, 3).join(", ").length());
default AnyM<W,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()
default <K> AnyM<W,MapX<K,ListX<T>>> groupBy(java.util.function.Function<? super T,? extends K> classifier)
Map<Integer, List<Integer>> map1 = of(1, 2, 3, 4).groupBy(i -> i % 2);
assertEquals(asList(2, 4), map1.get(0));
assertEquals(asList(1, 3), map1.get(1));
assertEquals(2, map1.size());
default AnyM<W,java.util.Optional<T>> findFirst()
ReactiveSeq.of(1,2,3,4,5).filter(it -> it <3).findFirst().get();
//3
(deterministic)default AnyM<W,java.lang.Boolean> startsWithIterable(java.lang.Iterable<T> iterable)
assertTrue(ReactiveSeq.of(1,2,3,4).startsWith(Arrays.asList(1,2,3)));
iterable
- default AnyM<W,java.lang.Boolean> startsWith(java.util.stream.Stream<T> stream)
assertTrue(ReactiveSeq.of(1,2,3,4).startsWith(Arrays.asList(1,2,3).iterator()))
iterator
- default AnyM<W,java.lang.Boolean> endsWithIterable(java.lang.Iterable<T> iterable)
assertTrue(ReactiveSeq.of(1,2,3,4,5,6)
.endsWith(Arrays.asList(5,6)));
iterable
- Values to checkdefault AnyM<W,java.lang.Boolean> endsWith(java.util.stream.Stream<T> stream)
assertTrue(ReactiveSeq.of(1,2,3,4,5,6)
.endsWith(Stream.of(5,6)));
stream
- Values to checkdefault <R> AnyM<W,R> toNested(java.util.function.Function<? super ConvertableSequence<T>,? extends R> fn)
default AnyM<W,T> firstValue()
assertThat(ReactiveSeq.of(1,2,3,4)
.map(u->{throw new RuntimeException();})
.recover(e->"hello")
.firstValue(),equalTo("hello"));
default AnyM<W,T> singleUnsafe()
//1
ReactiveSeq.of(1).singleUnsafe();
//UnsupportedOperationException
ReactiveSeq.of().singleUnsafe();
//UnsupportedOperationException
ReactiveSeq.of(1,2,3).singleUnsafe();
default AnyM<W,Maybe<T>> single()
//Optional[1]
ReactiveSeq.of(1).singleUnsafe();
//Optional.zero
ReactiveSeq.of().singleOpional();
//Optional.zero
ReactiveSeq.of(1,2,3).singleUnsafe();
default AnyM<W,Maybe<T>> get(long index)
assertThat(ReactiveSeq.of(1,2,3,4,5).elementAt(2).get(),equalTo(3));
index
- to extract element fromdefault HotStream<T> schedule(java.lang.String cron, java.util.concurrent.ScheduledExecutorService ex)
//run at 8PM every night
ReactiveSeq.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
.schedule("0 20 * * *",Executors.newScheduledThreadPool(1));
Connect to the Scheduled Stream
HotStream<Data> dataStream = ReactiveSeq.generate(() -> "next job:" + formatDate(new Date())).map(this::processJob)
.schedule("0 20 * * *", Executors.newScheduledThreadPool(1));
data.connect()
.forEach(this::logToDB);
cron
- Expression that determines when each job will runex
- ScheduledExecutorServicedefault HotStream<T> scheduleFixedDelay(long delay, java.util.concurrent.ScheduledExecutorService ex)
//run every 60 seconds after last job completes
ReactiveSeq.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
.scheduleFixedDelay(60_000,Executors.newScheduledThreadPool(1));
Connect to the Scheduled Stream
HotStream<Data> dataStream = ReactiveSeq.generate(() -> "next job:" + formatDate(new Date())).map(this::processJob)
.scheduleFixedDelay(60_000, Executors.newScheduledThreadPool(1));
data.connect().forEach(this::logToDB);
delay
- Between last element completes passing through the Stream
until the next one startsex
- ScheduledExecutorServicedefault HotStream<T> scheduleFixedRate(long rate, java.util.concurrent.ScheduledExecutorService ex)
//run every 60 seconds
ReactiveSeq.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
.scheduleFixedRate(60_000,Executors.newScheduledThreadPool(1));
Connect to the Scheduled Stream
HotStream<Data> dataStream = ReactiveSeq.generate(() -> "next job:" + formatDate(new Date())).map(this::processJob)
.scheduleFixedRate(60_000, Executors.newScheduledThreadPool(1));
data.connect()
.forEach(this::logToDB);
rate
- Time in millis between job runsex
- ScheduledExecutorService