public class SequenceMImpl<T> extends java.lang.Object implements Unwrapable, SequenceM<T>, java.lang.Iterable<T>
| Constructor and Description |
|---|
SequenceMImpl(java.util.stream.Stream<T> stream) |
SequenceMImpl(java.util.stream.Stream<T> stream,
ReversableSpliterator rev) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
allMatch(java.util.function.Predicate<? super T> c)
True if predicate matches all elements when Monad converted to a Stream
|
AnyM<T> |
anyM() |
boolean |
anyMatch(java.util.function.Predicate<? super T> c)
True if a single element matches when Monad converted to a Stream
|
SequenceM<T> |
append(T... values)
Append values to the end of this SequenceM
|
SequenceM<T> |
appendStream(java.util.stream.Stream<T> stream)
Append Stream to this SequenceM
|
SequenceM<java.util.List<T>> |
batchBySize(int size)
Batch elements in a Stream by size into Lists
|
<C extends java.util.Collection<T>> |
batchBySize(int size,
java.util.function.Supplier<C> factory)
Batch elements in a Stream by size into a collection created by the
supplied factory
|
SequenceM<java.util.List<T>> |
batchBySizeAndTime(int size,
long time,
java.util.concurrent.TimeUnit t)
Batch elements by size into a List
|
<C extends java.util.Collection<? super T>> |
batchBySizeAndTime(int size,
long time,
java.util.concurrent.TimeUnit unit,
java.util.function.Supplier<C> factory)
Batch elements by size into a collection created by the supplied factory
|
SequenceM<java.util.List<T>> |
batchByTime(long time,
java.util.concurrent.TimeUnit t)
Batch elements in a Stream by time period
|
<C extends java.util.Collection<T>> |
batchByTime(long time,
java.util.concurrent.TimeUnit unit,
java.util.function.Supplier<C> factory)
Batch elements by time into a collection created by the supplied factory
|
SequenceM<java.util.List<T>> |
batchUntil(java.util.function.Predicate<? super T> predicate)
Create a SequenceM batched by List, where each batch is populated until
the predicate holds
|
<C extends java.util.Collection<? super T>> |
batchUntil(java.util.function.Predicate<? super T> predicate,
java.util.function.Supplier<C> factory)
Create a SequenceM batched by a Collection, where each batch is populated
until the predicate holds
|
SequenceM<java.util.List<T>> |
batchWhile(java.util.function.Predicate<? super T> predicate)
Create a SequenceM batched by List, where each batch is populated while
the predicate holds
|
<C extends java.util.Collection<? super T>> |
batchWhile(java.util.function.Predicate<? super T> predicate,
java.util.function.Supplier<C> factory)
Create a SequenceM batched by a Collection, where each batch is populated
while the predicate holds
|
<U> SequenceM<U> |
cast(java.lang.Class<U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException. |
void |
close() |
<R,A> R |
collect(java.util.stream.Collector<? super T,A,R> collector)
Mutable reduction / collection over this Monad converted to a Stream
|
java.util.List |
collect(java.util.stream.Stream<java.util.stream.Collector> collectors)
Apply multiple collectors Simulataneously to this Monad
|
<R> R |
collect(java.util.function.Supplier<R> supplier,
java.util.function.BiConsumer<R,? super T> accumulator,
java.util.function.BiConsumer<R,R> combiner) |
org.jooq.lambda.Collectable<T> |
collectable()
Narrow this class to a Collectable
|
<R> java.util.List<R> |
collectIterable(java.lang.Iterable<java.util.stream.Collector> collectors)
Apply multiple Collectors, simultaneously to a Stream
|
java.util.List |
collectStream(java.util.stream.Stream<java.util.stream.Collector> collectors)
Apply multiple collectors Simulataneously to this Monad
|
SequenceM<T> |
concat(java.util.stream.Stream<T> other) |
SequenceM<T> |
concat(T... other) |
SequenceM<T> |
concat(T other) |
long |
count() |
SequenceM<T> |
cycle()
Convert to a Stream with the values infinitely cycled
|
<R> SequenceM<R> |
cycle(java.lang.Class<R> monadC,
int times)
Convert to a Stream, repeating the resulting structure specified times
and lifting all values to the specified Monad type
|
SequenceM<T> |
cycle(int times)
Convert to a Stream with the values repeated specified times
|
SequenceM<T> |
cycle(Monoid<T> m,
int times)
Convert to a Stream with the result of a reduction operation repeated
specified times
|
SequenceM<T> |
cycleUntil(java.util.function.Predicate<? super T> predicate)
Repeat in a Stream until specified predicate holds
|
SequenceM<T> |
cycleWhile(java.util.function.Predicate<? super T> predicate)
Repeat in a Stream while specified predicate holds
|
SequenceM<T> |
debounce(long time,
java.util.concurrent.TimeUnit t)
Allow one element through per time period, drop all other elements in
that time period
|
SequenceM<T> |
deleteBetween(int start,
int end)
Delete elements between given indexes in a Stream
|
SequenceM<T> |
distinct() |
<U> SequenceM<T> |
distinct(java.util.function.Function<? super T,? extends U> keyExtractor) |
org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<T>> |
duplicateSequence()
Duplicate a Stream, buffers intermediate values, leaders may change positions so a limit
can be safely applied to the leading stream.
|
boolean |
endsWith(java.lang.Iterable<T> iterable)
assertTrue(SequenceM.of(1,2,3,4,5,6)
.endsWith(Arrays.asList(5,6)));
|
boolean |
endsWith(java.util.stream.Stream<T> iterable)
assertTrue(SequenceM.of(1,2,3,4,5,6)
.endsWith(Stream.of(5,6)));
|
SequenceM<T> |
filter(java.util.function.Predicate<? super T> fn) |
java.util.Optional<T> |
findAny() |
java.util.Optional<T> |
findFirst() |
T |
firstValue()
assertThat(SequenceM.of(1,2,3,4)
.map(u->{throw new RuntimeException();})
.recover(e->"hello")
.firstValue(),equalTo("hello"));
|
SequenceM<T> |
fixedDelay(long l,
java.util.concurrent.TimeUnit unit)
emit elements after a fixed delay
|
<R> SequenceM<R> |
flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> fn)
flatMap operation
|
<R> SequenceM<R> |
flatMapAnyM(java.util.function.Function<? super T,AnyM<? extends R>> fn)
Allows flatMap return type to be any Monad type
|
SequenceM<java.lang.String> |
flatMapBufferedReader(java.util.function.Function<? super T,java.io.BufferedReader> fn)
Perform a flatMap operation where the result will be a flattened stream of Strings
from the text loaded from the supplied BufferedReaders
|
SequenceM<java.lang.Character> |
flatMapCharSequence(java.util.function.Function<? super T,java.lang.CharSequence> fn)
Perform a flatMap operation where the result will be a flattened stream of Characters
from the CharSequence returned by the supplied function.
|
<R> SequenceM<R> |
flatMapCollection(java.util.function.Function<? super T,java.util.Collection<? extends R>> fn)
Convenience method & performance optimisation
flatMapping to a Stream will result in the Stream being converted to a List, if the host Monad
type is not a Stream.
|
<R> SequenceM<R> |
flatMapCompletableFuture(java.util.function.Function<? super T,java.util.concurrent.CompletableFuture<? extends R>> fn)
flatMap to CompletableFuture - will block until Future complete, although (for non-blocking behaviour use AnyM
wrapping CompletableFuture and flatMap to Stream there)
|
SequenceM<java.lang.String> |
flatMapFile(java.util.function.Function<? super T,java.io.File> fn)
Perform a flatMap operation where the result will be a flattened stream of Strings
from the text loaded from the supplied files.
|
<R> SequenceM<R> |
flatMapOptional(java.util.function.Function<? super T,java.util.Optional<? extends R>> fn)
flatMap to optional - will result in null values being removed
|
<R> SequenceM<R> |
flatMapStream(java.util.function.Function<? super T,java.util.stream.BaseStream<? extends R,?>> fn)
flatMap operation
|
java.util.stream.DoubleStream |
flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper) |
java.util.stream.IntStream |
flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper) |
java.util.stream.LongStream |
flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper) |
SequenceM<java.lang.String> |
flatMapURL(java.util.function.Function<? super T,java.net.URL> fn)
Perform a flatMap operation where the result will be a flattened stream of Strings
from the text loaded from the supplied URLs
|
<T1> SequenceM<T1> |
flatten()
join / flatten one level of a nested hierarchy
|
T |
foldLeft(Monoid<T> reducer)
SequenceM.of("a","b","c").foldLeft(Reducers.toString(""));
// "abc"
|
T |
foldLeft(T identity,
java.util.function.BinaryOperator<T> accumulator)
foldLeft : immutable reduction from left to right
|
<T> T |
foldLeftMapToType(Monoid<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
|
T |
foldRight(Monoid<T> reducer)
SequenceM.of("a","b","c").foldRight(Reducers.toString(""));
// "cab"
|
T |
foldRight(T identity,
java.util.function.BinaryOperator<T> accumulator)
Immutable reduction from right to left
|
<U> U |
foldRight(U seed,
java.util.function.BiFunction<? super T,U,U> function)
Immutable reduction from right to left
|
<T> T |
foldRightMapToType(Monoid<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
|
void |
forEach(java.util.function.Consumer<? super T> action) |
<R1,R> SequenceM<R> |
forEach2(java.util.function.Function<? super T,? extends java.util.stream.BaseStream<R1,?>> stream1,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction)
Perform a two level nested internal iteration over this Stream and the supplied stream
|
<R1,R> SequenceM<R> |
forEach2(java.util.function.Function<? super T,? extends java.util.stream.BaseStream<R1,?>> stream1,
java.util.function.Function<? super T,java.util.function.Function<? super R1,java.lang.Boolean>> filterFunction,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction)
Perform a two level nested internal iteration over this Stream and the supplied stream
|
<R1,R2,R> SequenceM<R> |
forEach3(java.util.function.Function<? super T,? extends java.util.stream.BaseStream<R1,?>> stream1,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends java.util.stream.BaseStream<R2,?>>> stream2,
java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,? extends R>>> yieldingFunction)
Perform a three level nested internal iteration over this Stream and the supplied streams
|
<R1,R2,R> SequenceM<R> |
forEach3(java.util.function.Function<? super T,? extends java.util.stream.BaseStream<R1,?>> stream1,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends java.util.stream.BaseStream<R2,?>>> stream2,
java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,java.lang.Boolean>>> filterFunction,
java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,? extends R>>> yieldingFunction)
Perform a three level nested internal iteration over this Stream and the supplied streams
|
<X extends java.lang.Throwable> |
forEachEvent(java.util.function.Consumer<? super T> consumerElement,
java.util.function.Consumer<? super java.lang.Throwable> consumerError,
java.lang.Runnable onComplete)
Perform a forEach operation over the Stream capturing any elements and errors in the supplied consumers
when the entire Stream has been processed an onComplete event will be recieved.
|
void |
forEachOrdered(java.util.function.Consumer<? super T> action) |
<X extends java.lang.Throwable> |
forEachWithError(java.util.function.Consumer<? super T> consumerElement,
java.util.function.Consumer<? super java.lang.Throwable> consumerError)
Perform a forEach operation over the Stream capturing any elements and errors in the supplied consumers,
|
<X extends java.lang.Throwable> |
forEachX(long numberOfElements,
java.util.function.Consumer<? super T> consumer)
Perform a forEach operation over the Stream, without closing it, consuming only the specified number of elements from
the Stream, at this time.
|
<X extends java.lang.Throwable> |
forEachXEvents(long numberOfElements,
java.util.function.Consumer<? super T> consumer,
java.util.function.Consumer<? super java.lang.Throwable> consumerError,
java.lang.Runnable onComplete)
Perform a forEach operation over the Stream without closing it, capturing any elements and errors in the supplied consumers, but only consuming
the specified number of elements from the Stream, at this time.
|
<X extends java.lang.Throwable> |
forEachXWithError(long numberOfElements,
java.util.function.Consumer<? super T> consumer,
java.util.function.Consumer<? super java.lang.Throwable> consumerError)
Perform a forEach operation over the Stream without closing it, capturing any elements and errors in the supplied consumers, but only consuming
the specified number of elements from the Stream, at this time.
|
java.lang.String |
format() |
FutureOperations<T> |
futureOperations(java.util.concurrent.Executor exec)
Access asynchronous terminal operations (each returns a Future)
|
<K> java.util.Map<K,java.util.List<T>> |
groupBy(java.util.function.Function<? super T,? extends K> classifier)
Use classifier function to group elements in this Sequence into a Map
|
SequenceM<java.util.List<T>> |
grouped(int groupSize)
Group elements in a Stream
|
HeadAndTail<T> |
headAndTail()
extract head and tail together, where head is expected to be present
|
java.util.Optional<HeadAndTail<T>> |
headAndTailOptional()
extract head and tail together, where no head or tail may be present
|
HotStream<T> |
hotStream(java.util.concurrent.Executor e)
Turns this SequenceM into a HotStream, a connectable Stream, being executed on a thread on the
supplied executor, that is producing data.
|
SequenceM<T> |
insertAt(int pos,
T... values)
Insert data into a stream at given position
|
SequenceM<T> |
insertStreamAt(int pos,
java.util.stream.Stream<T> stream)
Insert a Stream into the middle of this stream at the specified position
|
SequenceM<T> |
intersperse(T value)
Returns a stream with a given value interspersed between any two values
of this stream.
|
boolean |
isParallel() |
java.util.Iterator<T> |
iterator() |
SequenceM<T> |
jitter(long l)
Introduce a random jitter / time delay between the emission of elements
|
java.lang.String |
join()
assertEquals("123".length(),of(1, 2, 3).join().length());
|
java.lang.String |
join(java.lang.String sep)
assertEquals("1, 2, 3".length(), of(1, 2, 3).join(", ").length());
|
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());
|
SequenceM<T> |
limit(long num)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().limit(2).toList(),equalTo(Arrays.asList(4,3))); |
SequenceM<T> |
limit(long time,
java.util.concurrent.TimeUnit unit)
Return all elements until specified time period has elapsed
|
SequenceM<T> |
limitLast(int num)
Limit results to the last x elements in a SequenceM
|
SequenceM<T> |
limitUntil(java.util.function.Predicate<? super T> p)
assertThat(anyM(Stream.of(4,3,6,7)).limitUntil(i->i==6).toList(),equalTo(Arrays.asList(4,3))); |
SequenceM<T> |
limitWhile(java.util.function.Predicate<? super T> p)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().sorted().limitWhile(i->i<6).toList(),equalTo(Arrays.asList(3,4))); |
<R> SequenceM<R> |
map(java.util.function.Function<? super T,? extends R> fn) |
<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
|
<R> R |
mapReduce(Monoid<R> 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
|
java.util.stream.DoubleStream |
mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper) |
java.util.stream.IntStream |
mapToInt(java.util.function.ToIntFunction<? super T> mapper) |
java.util.stream.LongStream |
mapToLong(java.util.function.ToLongFunction<? super T> mapper) |
java.util.Optional<T> |
max(java.util.Comparator<? super T> comparator) |
<C extends java.lang.Comparable<? super C>> |
maxBy(java.util.function.Function<? super T,? extends C> f)
Extract the maximum as determined by the supplied function
|
java.util.Optional<T> |
min(java.util.Comparator<? super T> comparator) |
<U extends java.lang.Comparable<? super U>> |
minBy(java.util.function.Function<? super T,? extends U> function)
Extract the minimum as determined by supplied function
|
boolean |
noneMatch(java.util.function.Predicate<? super T> c) |
<U> SequenceM<U> |
ofType(java.lang.Class<U> type)
Keep only those elements in a stream that are of a given type.
|
SequenceM<T> |
onClose(java.lang.Runnable closeHandler) |
SequenceM<T> |
onEmpty(T value) |
SequenceM<T> |
onEmptyGet(java.util.function.Supplier<T> supplier) |
<X extends java.lang.Throwable> |
onEmptyThrow(java.util.function.Supplier<X> supplier) |
SequenceM<T> |
onePer(long time,
java.util.concurrent.TimeUnit t)
emit one element per time period
|
SequenceM<T> |
parallel() |
org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<T>> |
partitionSequence(java.util.function.Predicate<T> splitter)
Partition a Stream into two one a per element basis, based on predicate's boolean value
|
PausableHotStream<T> |
pausableHotStream(java.util.concurrent.Executor e)
Turns this SequenceM into a HotStream, a connectable & pausable Stream, being executed on a thread on the
supplied executor, that is producing data.
|
SequenceM<T> |
peek(java.util.function.Consumer<? super T> c) |
SequenceM<T> |
prepend(T... values)
Prepend given values to the start of the Stream
|
SequenceM<T> |
prependStream(java.util.stream.Stream<T> stream)
Prepend Stream to this SequenceM
|
HotStream<T> |
primedHotStream(java.util.concurrent.Executor e)
Return a HotStream that will start emitting data when the first connecting Stream connects.
|
PausableHotStream<T> |
primedPausableHotStream(java.util.concurrent.Executor e)
Return a pausable HotStream that will start emitting data when the first connecting Stream connects.
|
org.jooq.lambda.tuple.Tuple4<SequenceM<T>,SequenceM<T>,SequenceM<T>,SequenceM<T>> |
quadruplicate()
Makes four copies of a Stream
Buffers intermediate values, leaders may change positions so a limit
can be safely applied to the leading stream.
|
<EX extends java.lang.Throwable> |
recover(java.lang.Class<EX> exceptionClass,
java.util.function.Function<EX,? extends T> fn)
Recover from a particular exception type
|
SequenceM<T> |
recover(java.util.function.Function<java.lang.Throwable,? extends T> fn)
Recover from an exception with an alternative value
|
java.util.Optional<T> |
reduce(java.util.function.BinaryOperator<T> accumulator) |
java.util.List<T> |
reduce(java.lang.Iterable<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 streamedStreamUtils.sequenceM() first.
|
T |
reduce(Monoid<T> reducer)
SequenceM.of("hello","2","world","4").reduce(Reducers.toString(","));
//hello,2,world,4
|
java.util.List<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 streamedStreamUtils.sequenceM() first.
|
T |
reduce(T identity,
java.util.function.BinaryOperator<T> accumulator) |
<U> U |
reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator,
java.util.function.BinaryOperator<U> combiner) |
SequenceM<T> |
reverse() |
SequenceM<T> |
scanLeft(Monoid<T> monoid)
Scan left using supplied Monoid
|
<U> SequenceM<U> |
scanLeft(U seed,
java.util.function.BiFunction<U,? super T,U> function)
Scan left
|
SequenceM<T> |
scanRight(Monoid<T> monoid)
Scan right
|
<U> SequenceM<U> |
scanRight(U identity,
java.util.function.BiFunction<? super T,U,U> combiner)
Scan right
|
HotStream<T> |
schedule(java.lang.String cron,
java.util.concurrent.ScheduledExecutorService ex)
Execute this Stream on a schedule
|
HotStream<T> |
scheduleFixedDelay(long delay,
java.util.concurrent.ScheduledExecutorService ex)
Execute this Stream on a schedule
|
HotStream<T> |
scheduleFixedRate(long rate,
java.util.concurrent.ScheduledExecutorService ex)
Execute this Stream on a schedule
|
SequenceM<T> |
sequential() |
SequenceM<T> |
shuffle() |
SequenceM<T> |
shuffle(java.util.Random random) |
SequenceM<T> |
skip(long num)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().skip(2).toList(),equalTo(Arrays.asList(6,7))); |
SequenceM<T> |
skip(long time,
java.util.concurrent.TimeUnit unit)
Skip all elements until specified time period has passed
|
SequenceM<T> |
skipLast(int num)
assertThat(SequenceM.of(1,2,3,4,5) .skipLast(2)
.collect(Collectors.toList()),equalTo(Arrays.asList(1,2,3)));
|
SequenceM<T> |
skipUntil(java.util.function.Predicate<? super T> p)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().skipUntil(i->i==6).toList(),equalTo(Arrays.asList(6,7))); |
SequenceM<T> |
skipWhile(java.util.function.Predicate<? super T> p)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().sorted().skipWhile(i->i<6).toList(),equalTo(Arrays.asList(6,7)));
|
SequenceM<T> |
slice(long from,
long to) |
SequenceM<java.util.List<T>> |
sliding(int windowSize)
Create a sliding view over this Sequence
|
SequenceM<java.util.List<T>> |
sliding(int windowSize,
int increment)
Create a sliding view over this Sequence
|
SequenceM<T> |
sorted()
assertThat(SequenceM.of(4,3,6,7)).sorted().toList(),equalTo(Arrays.asList(3,4,6,7))); |
SequenceM<T> |
sorted(java.util.Comparator<? super T> c)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().sorted((a,b) -> b-a).toList(),equalTo(Arrays.asList(7,6,4,3)));
|
<U extends java.lang.Comparable<? super U>> |
sorted(java.util.function.Function<? super T,? extends U> function) |
org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<T>> |
splitAt(int where)
Split at supplied location
|
org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<T>> |
splitBy(java.util.function.Predicate<T> splitter)
Split stream at point where predicate no longer holds
|
java.util.Spliterator<T> |
spliterator() |
org.jooq.lambda.tuple.Tuple2<java.util.Optional<T>,SequenceM<T>> |
splitSequenceAtHead()
Split a Stream at it's head (similar to headAndTail)
|
boolean |
startsWith(java.lang.Iterable<T> iterable)
assertTrue(StreamUtils.sequenceM(Stream.of(1,2,3,4)).startsWith(Arrays.asList(1,2,3)));
|
boolean |
startsWith(java.util.Iterator<T> iterator)
assertTrue(StreamUtils.sequenceM(Stream.of(1,2,3,4)).startsWith(Arrays.asList(1,2,3).iterator())) |
SequenceM<T> |
stream()
Unwrap this Monad into a Stream.
|
void |
subscribe(org.reactivestreams.Subscriber<? super T> s) |
java.lang.Object[] |
toArray() |
<A> A[] |
toArray(java.util.function.IntFunction<A[]> generator) |
<C extends java.util.Collection<T>> |
toCollection(java.util.function.Supplier<C> collectionFactory) |
java.util.concurrent.CompletableFuture<java.util.List<T>> |
toCompletableFuture()
CompletableFuture<List<String>> cf = anyM("hello","world")
.asSequence()
.unwrapCompletableFuture();
assertThat(cf.join(),equalTo(Arrays.asList("hello","world")));
|
java.util.Collection<T> |
toConcurrentLazyCollection()
Lazily converts this SequenceM into a Collection.
|
Streamable<T> |
toConcurrentLazyStreamable()
{
@code
Streamable<Integer> repeat = SequenceM.of(1, 2, 3, 4, 5, 6).map(i -> i + 2).toConcurrentLazyStreamable();
assertThat(repeat.sequenceM().toList(), equalTo(Arrays.asList(2, 4, 6, 8, 10, 12)));
assertThat(repeat.sequenceM().toList(), equalTo(Arrays.asList(2, 4, 6, 8, 10, 12)));
}
|
java.util.Collection<T> |
toLazyCollection()
Lazily converts this SequenceM into a Collection.
|
Streamable<T> |
toLazyStreamable() |
java.util.List<T> |
toList() |
java.util.Optional<java.util.List<T>> |
toOptional()
Type safe unwrap
|
java.util.Set<T> |
toSet() |
<T> java.util.stream.Stream<T> |
toStream()
Convert this SequenceM into a Stream
|
Streamable<T> |
toStreamable()
Streamable<Integer> repeat = SequenceM.of(1,2,3,4,5,6)
.map(i->i*2)
.toStreamable();
repeat.sequenceM().toList(); //Arrays.asList(2,4,6,8,10,12));
repeat.sequenceM().toList() //Arrays.asList(2,4,6,8,10,12));
|
org.jooq.lambda.tuple.Tuple3<SequenceM<T>,SequenceM<T>,SequenceM<T>> |
triplicate()
Triplicates a Stream
Buffers intermediate values, leaders may change positions so a limit
can be safely applied to the leading stream.
|
SequenceM<T> |
unordered() |
<R> R |
unwrap()
Deprecated.
|
java.util.stream.Stream<T> |
unwrapStream()
Type safe unwrap
|
SequenceM<Streamable<T>> |
windowBySizeAndTime(int size,
long time,
java.util.concurrent.TimeUnit t)
Create a Sequence of Streamables (replayable Streams / Sequences) where
each Streamable is populated up to a max size, or for max period of time
|
SequenceM<Streamable<T>> |
windowByTime(long time,
java.util.concurrent.TimeUnit t)
Create SequenceM of Streamables (replayable Streams / Sequences) where
each Streamable is populated within a specified time window
|
SequenceM<Streamable<T>> |
windowStatefullyWhile(java.util.function.BiPredicate<Streamable<? super T>,? super T> predicate)
Create SequenceM of Streamables (replayable Streams / Sequences) where
each Streamable is populated while the supplied bipredicate holds.
|
SequenceM<Streamable<T>> |
windowUntil(java.util.function.Predicate<? super T> predicate)
Create a Sequence of Streamables (replayable Streams / Sequences) where
each Streamable is populated until the supplied predicate holds.
|
SequenceM<Streamable<T>> |
windowWhile(java.util.function.Predicate<? super T> predicate)
Create a Sequence of Streamables (replayable Streams / Sequences) where
each Streamable is populated while the supplied predicate holds.
|
boolean |
xMatch(int num,
java.util.function.Predicate<? super T> c)
Check that there are specified number of matches of predicate in the Stream
|
SequenceM<T> |
xPer(int x,
long time,
java.util.concurrent.TimeUnit t)
emit x elements per time period
|
<S,R> SequenceM<R> |
zip(AnyM<? extends S> second,
java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Zip this SequenceM against any monad type.
|
<U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(org.jooq.lambda.Seq<U> other)
Zip 2 streams into one
|
<U,R> SequenceM<R> |
zip(org.jooq.lambda.Seq<U> other,
java.util.function.BiFunction<? super T,? super U,? extends R> zipper) |
<S> SequenceM<org.jooq.lambda.tuple.Tuple2<T,S>> |
zip(java.util.stream.Stream<S> second)
Zip 2 streams into one
|
<S,U> SequenceM<org.jooq.lambda.tuple.Tuple3<T,S,U>> |
zip3(java.util.stream.Stream<? extends S> second,
java.util.stream.Stream<? extends U> third)
zip 3 Streams into one
|
<T2,T3,T4> SequenceM<org.jooq.lambda.tuple.Tuple4<T,T2,T3,T4>> |
zip4(java.util.stream.Stream<T2> second,
java.util.stream.Stream<T3> third,
java.util.stream.Stream<T4> fourth)
zip 4 Streams into 1
|
<S,R> SequenceM<R> |
zipAnyM(AnyM<? extends S> second,
java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Zip this SequenceM against any monad type.
|
<S,R> SequenceM<R> |
zipSequence(SequenceM<? extends S> second,
java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Generic zip function.
|
<S,R> SequenceM<R> |
zipStream(java.util.stream.BaseStream<? extends S,? extends java.util.stream.BaseStream<? extends S,?>> second,
java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Zip this Monad with a Stream
|
<U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> |
zipStream(java.util.stream.Stream<U> other)
Zip 2 streams into one
|
SequenceM<org.jooq.lambda.tuple.Tuple2<T,java.lang.Long>> |
zipWithIndex()
Add an index to the current Stream
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcombinations, combinations, crossJoin, crossJoin, crossJoin, elapsed, elementAt, empty, fromDoubleStream, fromIntStream, fromIterable, fromIterator, fromList, fromLongStream, fromStream, generate, get, grouped, grouped, innerJoin, innerJoin, innerJoin, innerJoin, iterate, leftOuterJoin, leftOuterJoin, leftOuterJoin, leftOuterJoin, limitUntilClosed, of, onEmptySwitch, permutations, range, rangeLong, remove, retry, reversedListOf, reversedOf, rightOuterJoin, rightOuterJoin, rightOuterJoin, single, single, singleOptional, size, skipUntilClosed, subscriber, subStream, timestamp, trampoline, unzip, unzip3, unzip4window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, window, windowremoveAll, removeAll, removeAll, removeAll, retainAll, retainAll, retainAll, retainAllappend, append, append, append, cast, concat, concat, concat, concat, concat, contains, containsAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, containsAny, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, cycle, cycle, cycle, cycle, cycle, cycle, cycle, duplicate, duplicate, findFirst, findSingle, foldLeft, foldLeft, foldLeft, foldLeft, foldRight, foldRight, foldRight, generate, groupBy, groupBy, groupBy, groupBy, groupBy, grouped, grouped, grouped, grouped, grouped, grouped, intersperse, isEmpty, isNotEmpty, join, join, join, join, join, limit, limitUntil, limitUntilClosed, limitWhile, limitWhileClosed, limitWhileClosed, ofType, partition, partition, prepend, prepend, prepend, prepend, print, print, printErr, printOut, range, range, range, range, range, range, range, range, range, range, range, rangeClosed, rangeClosed, rangeClosed, rangeClosed, rangeClosed, rangeClosed, rangeClosed, rangeClosed, rangeClosed, rangeClosed, rangeClosed, rangeClosed, reverse, reverse, reverse, scanLeft, scanLeft, scanLeft, scanRight, scanRight, scanRight, seq, seq, seq, seq, seq, seq, seq, seq, seq, seq, seq, seq, shuffle, shuffle, shuffle, shuffle, shuffle, shuffle, skip, skipUntil, skipUntilClosed, skipWhile, skipWhileClosed, skipWhileClosed, slice, sliding, sorted, splitAt, splitAt, splitAtHead, splitAtHead, toCollection, toList, toMap, toMap, toSet, toString, toString, unfold, unzip, unzip, unzip, unzip, unzip, unzip, unzip, unzip, unzip, unzip, unzip, unzip, window, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zipWithIndex, zipWithIndex, zipWithIndexavg, avg, avgDouble, avgInt, avgLong, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, collect, count, countDistinct, countDistinct, countDistinctBy, countDistinctBy, max, max, max, maxBy, median, median, medianBy, medianBy, min, min, min, minBy, mode, percentile, percentile, percentileBy, percentileBy, sum, sum, sumDouble, sumInt, sumLong, toList, toMap, toSet, toString, toStringavg, avg, avgDouble, avgInt, avgLong, count, countDistinct, countDistinct, countDistinctBy, countDistinctBy, max, max, max, maxBy, median, median, medianBy, medianBy, min, min, min, minBy, mode, percentile, percentile, percentileBy, percentileBy, sum, sum, sumDouble, sumInt, sumLong, toList, toMap, toSet, toString, toStringpublic SequenceMImpl(java.util.stream.Stream<T> stream)
public SequenceMImpl(java.util.stream.Stream<T> stream, ReversableSpliterator rev)
public HotStream<T> schedule(java.lang.String cron, java.util.concurrent.ScheduledExecutorService ex)
SequenceM
//run at 8PM every night
SequenceeM.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
.schedule("0 20 * * *",Executors.newScheduledThreadPool(1));
Connect to the Scheduled Stream
{
@code
HotStream<Data> dataStream = SequenceeM.generate(() -> "next job:" + formatDate(new Date())).map(this::processJob)
.schedule("0 20 * * *", Executors.newScheduledThreadPool(1));
data.connect().forEach(this::logToDB);
}
public HotStream<T> scheduleFixedDelay(long delay, java.util.concurrent.ScheduledExecutorService ex)
SequenceM
//run every 60 seconds after last job completes
SequenceeM.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
.scheduleFixedDelay(60_000,Executors.newScheduledThreadPool(1));
Connect to the Scheduled Stream
{
@code
HotStream<Data> dataStream = SequenceeM.generate(() -> "next job:" + formatDate(new Date())).map(this::processJob)
.scheduleFixedDelay(60_000, Executors.newScheduledThreadPool(1));
data.connect().forEach(this::logToDB);
}
scheduleFixedDelay in interface SequenceM<T>delay - Between last element completes passing through the Stream
until the next one startsex - ScheduledExecutorServicepublic HotStream<T> scheduleFixedRate(long rate, java.util.concurrent.ScheduledExecutorService ex)
SequenceM
//run every 60 seconds
SequenceeM.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
.scheduleFixedRate(60_000,Executors.newScheduledThreadPool(1));
Connect to the Scheduled Stream
{
@code
HotStream<Data> dataStream = SequenceeM.generate(() -> "next job:" + formatDate(new Date())).map(this::processJob)
.scheduleFixedRate(60_000, Executors.newScheduledThreadPool(1));
data.connect().forEach(this::logToDB);
}
scheduleFixedRate in interface SequenceM<T>rate - Time in millis between job runsex - ScheduledExecutorService@Deprecated public final <R> R unwrap()
unwrap in interface SequenceM<T>unwrap in interface Unwrapablepublic final <T1> SequenceM<T1> flatten()
assertThat(SequenceM.<Integer>of(Arrays.asList(1,2)).flatten().toList().size(),equalTo(asList(1, 2).size()));
// or more advanced example
AnyM<AnyM<Integer>> applied =anyM(Optional.of(2))
.simpleFilter(anyM(Streamable.of( (Integer a)->a>5 ,(Integer a) -> a<3)));
assertThat(applied.toSequence().flatten().toList(),equalTo(Arrays.asList(2)));
public final java.util.stream.Stream<T> unwrapStream()
Stream<String> stream = anyM("hello","world").asSequence().unwrapStream();
assertThat(stream.collect(Collectors.toList()),equalTo(Arrays.asList("hello","world")));
public final java.util.Optional<java.util.List<T>> toOptional()
Optional<List<String>> stream = anyM("hello","world")
.asSequence()
.unwrapOptional();
assertThat(stream.get(),equalTo(Arrays.asList("hello","world")));
toOptional in interface SequenceM<T>public final java.util.concurrent.CompletableFuture<java.util.List<T>> toCompletableFuture()
CompletableFuture<List<String>> cf = anyM("hello","world")
.asSequence()
.unwrapCompletableFuture();
assertThat(cf.join(),equalTo(Arrays.asList("hello","world")));
toCompletableFuture in interface SequenceM<T>public final SequenceM<T> cycle(int times)
assertThat(anyM(Stream.of(1,2,2)).asSequence()
.cycle(3).collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,2,1,2,2,1,2,2)));
public final SequenceM<T> cycle()
assertEquals(asList(1, 1, 1, 1, 1,1),of(1).cycle().limit(6).toList());
public final org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<T>> duplicateSequence()
Tuple2<SequenceM<Integer>, SequenceM<Integer>> copies =of(1,2,3,4,5,6).duplicate();
assertTrue(copies.v1.anyMatch(i->i==2));
assertTrue(copies.v2.anyMatch(i->i==2));
duplicateSequence in interface SequenceM<T>public final org.jooq.lambda.tuple.Tuple3<SequenceM<T>,SequenceM<T>,SequenceM<T>> triplicate()
Tuple3<SequenceM<Tuple3<T1,T2,T3>>,SequenceM<Tuple3<T1,T2,T3>>,SequenceM<Tuple3<T1,T2,T3>>> Tuple3 = sequence.triplicate();
triplicate in interface SequenceM<T>public final org.jooq.lambda.tuple.Tuple4<SequenceM<T>,SequenceM<T>,SequenceM<T>,SequenceM<T>> quadruplicate()
Tuple4<SequenceM<Tuple4<T1,T2,T3,T4>>,SequenceM<Tuple4<T1,T2,T3,T4>>,SequenceM<Tuple4<T1,T2,T3,T4>>,SequenceM<Tuple4<T1,T2,T3,T4>>> quad = sequence.quadruplicate();
quadruplicate in interface SequenceM<T>public final org.jooq.lambda.tuple.Tuple2<java.util.Optional<T>,SequenceM<T>> splitSequenceAtHead()
SequenceM.of(1,2,3).splitAtHead()
//Optional[1], SequenceM[2,3]
splitSequenceAtHead in interface SequenceM<T>public final org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<T>> splitAt(int where)
SequenceM.of(1,2,3).splitAt(1)
//SequenceM[1], SequenceM[2,3]
public final org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<T>> splitBy(java.util.function.Predicate<T> splitter)
SequenceM.of(1, 2, 3, 4, 5, 6).splitBy(i->i<4)
//SequenceM[1,2,3] SequenceM[4,5,6]
public final org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<T>> partitionSequence(java.util.function.Predicate<T> splitter)
SequenceM.of(1, 2, 3, 4, 5, 6).partition(i -> i % 2 != 0)
//SequenceM[1,3,5], SequenceM[2,4,6]
partitionSequence in interface SequenceM<T>public final SequenceM<T> cycle(Monoid<T> m, int times)
List<Integer> list = AsGenericMonad,asStreamUtils.sequenceM(Stream.of(1,2,2))
.cycle(Reducers.toCountInt(),3)
.collect(Collectors.toList());
//is asList(3,3,3);
public final <R> SequenceM<R> cycle(java.lang.Class<R> monadC, int times)
{
@code
List<Optional<Integer>> list = StreamUtils.sequenceM(Stream.of(1, 2)).cycle(Optional.class,
2).toList();
// is asList(Optional.of(1),Optional.of(2),Optional.of(1),Optional.of(2) ));
}
public final SequenceM<T> cycleWhile(java.util.function.Predicate<? super T> predicate)
count =0;
assertThat(anyM(Stream.of(1,2,2)).asSequence()
.cycleWhile(next -> count++<6)
.collect(Collectors.toList()),equalTo(Arrays.asList(1,2,2,1,2,2)));
cycleWhile in interface SequenceM<T>predicate - repeat while truepublic final SequenceM<T> cycleUntil(java.util.function.Predicate<? super T> predicate)
count =0;
assertThat(anyM(Stream.of(1,2,2)).asSequence()
.cycleUntil(next -> count++>6)
.collect(Collectors.toList()),equalTo(Arrays.asList(1,2,2,1,2,2,1)));
cycleUntil in interface SequenceM<T>predicate - repeat while truepublic final <S> SequenceM<org.jooq.lambda.tuple.Tuple2<T,S>> zip(java.util.stream.Stream<S> second)
List<Tuple2<Integer, String>> list = of(1, 2).zip(of("a", "b", "c", "d")).toList();
// [[1,"a"],[2,"b"]]
zip in interface org.jooq.lambda.Seq<T>public final <S,U> SequenceM<org.jooq.lambda.tuple.Tuple3<T,S,U>> zip3(java.util.stream.Stream<? extends S> second, java.util.stream.Stream<? extends U> third)
List<Tuple3<Integer,Integer,Character>> list =
of(1,2,3,4,5,6).zip3(of(100,200,300,400),of('a','b','c'))
.collect(Collectors.toList());
//[[1,100,'a'],[2,200,'b'],[3,300,'c']]
public final <T2,T3,T4> SequenceM<org.jooq.lambda.tuple.Tuple4<T,T2,T3,T4>> zip4(java.util.stream.Stream<T2> second, java.util.stream.Stream<T3> third, java.util.stream.Stream<T4> fourth)
List<Tuple4<Integer,Integer,Character,String>> list =
of(1,2,3,4,5,6).zip4(of(100,200,300,400),of('a','b','c'),of("hello","world"))
.collect(Collectors.toList());
//[[1,100,'a',"hello"],[2,200,'b',"world"]]
public final SequenceM<org.jooq.lambda.tuple.Tuple2<T,java.lang.Long>> zipWithIndex()
assertEquals(asList(new Tuple2("a", 0L), new Tuple2("b", 1L)), of("a", "b").zipWithIndex().toList());
zipWithIndex in interface SequenceM<T>zipWithIndex in interface org.jooq.lambda.Seq<T>public final <S,R> SequenceM<R> zipSequence(SequenceM<? extends S> second, java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
{
@code
Stream<List<Integer>> zipped = asStreamUtils.sequenceM(Stream.of(1, 2, 3)).zip(
asStreamUtils.sequenceM(Optional.of(2)), (a, b) -> Arrays.asList(a, b));
// [[1,2]]
}
zipSequence in interface SequenceM<T>second - Monad to zip withzipper - Zipping functionpublic final <S,R> SequenceM<R> zip(AnyM<? extends S> second, java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Stream<List<Integer>> zipped = anyM(Stream.of(1,2,3))
.asSequence()
.zip(anyM(Optional.of(2)),
(a,b) -> Arrays.asList(a,b)).toStream();
List<Integer> zip = zipped.collect(Collectors.toList()).get(0);
assertThat(zip.get(0),equalTo(1));
assertThat(zip.get(1),equalTo(2));
public final <S,R> SequenceM<R> zipStream(java.util.stream.BaseStream<? extends S,? extends java.util.stream.BaseStream<? extends S,?>> second, java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
{
@code
Stream<List<Integer>> zipped = asStreamUtils.sequenceM(Stream.of(1, 2, 3)).zip(
Stream.of(2, 3, 4), (a, b) -> Arrays.asList(a, b));
// [[1,2][2,3][3,4]]
}
public final SequenceM<java.util.List<T>> sliding(int windowSize)
List<List<Integer>> list = anyM(Stream.of(1,2,3,4,5,6))
.asSequence()
.sliding(2)
.collect(Collectors.toList());
assertThat(list.get(0),hasItems(1,2));
assertThat(list.get(1),hasItems(2,3));
public final SequenceM<java.util.List<T>> sliding(int windowSize, int increment)
List<List<Integer>> list = anyM(Stream.of(1,2,3,4,5,6))
.asSequence()
.sliding(3,2)
.collect(Collectors.toList());
assertThat(list.get(0),hasItems(1,2,3));
assertThat(list.get(1),hasItems(3,4,5));
public final SequenceM<java.util.List<T>> grouped(int groupSize)
{
@code
List<List<Integer>> list = StreamUtils.sequenceM(Stream.of(1, 2, 3, 4, 5, 6)).grouped(3)
.collect(Collectors.toList());
assertThat(list.get(0), hasItems(1, 2, 3));
assertThat(list.get(1), hasItems(4, 5, 6));
}
public final <K> java.util.Map<K,java.util.List<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());
public final SequenceM<T> scanLeft(Monoid<T> monoid)
assertEquals(asList("", "a", "ab", "abc"),StreamUtils.sequenceM(Stream.of("a", "b", "c")).scanLeft(Reducers.toString("")).toList());
public final <U> SequenceM<U> scanLeft(U seed, java.util.function.BiFunction<U,? super T,U> function)
assertThat(of("a", "b", "c").scanLeft("", String::concat).toList().size(),
is(4));
public final SequenceM<T> scanRight(Monoid<T> monoid)
assertThat(of("a", "b", "c").scanRight(Monoid.of("", String::concat)).toList().size(),
is(asList("", "c", "bc", "abc").size()));
public final <U> SequenceM<U> scanRight(U identity, java.util.function.BiFunction<? super T,U,U> combiner)
assertThat(of("a", "ab", "abc").map(str->str.length()).scanRight(0, (t, u) -> u + t).toList().size(),
is(asList(0, 3, 5, 6).size()));
public final SequenceM<T> sorted()
assertThat(SequenceM.of(4,3,6,7)).sorted().toList(),equalTo(Arrays.asList(3,4,6,7)));
public final SequenceM<T> sorted(java.util.Comparator<? super T> c)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().sorted((a,b) -> b-a).toList(),equalTo(Arrays.asList(7,6,4,3)));
public final SequenceM<T> skip(long num)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().skip(2).toList(),equalTo(Arrays.asList(6,7)));
public final SequenceM<T> skipWhile(java.util.function.Predicate<? super T> p)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().sorted().skipWhile(i->i<6).toList(),equalTo(Arrays.asList(6,7)));
public final SequenceM<T> skipUntil(java.util.function.Predicate<? super T> p)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().skipUntil(i->i==6).toList(),equalTo(Arrays.asList(6,7)));
public final SequenceM<T> limit(long num)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().limit(2).toList(),equalTo(Arrays.asList(4,3)));
public final SequenceM<T> limitWhile(java.util.function.Predicate<? super T> p)
assertThat(anyM(Stream.of(4,3,6,7)).asSequence().sorted().limitWhile(i->i<6).toList(),equalTo(Arrays.asList(3,4)));
limitWhile in interface SequenceM<T>limitWhile in interface org.jooq.lambda.Seq<T>p - Limit while predicate is truepublic final SequenceM<T> limitUntil(java.util.function.Predicate<? super T> p)
assertThat(anyM(Stream.of(4,3,6,7)).limitUntil(i->i==6).toList(),equalTo(Arrays.asList(4,3)));
limitUntil in interface SequenceM<T>limitUntil in interface org.jooq.lambda.Seq<T>p - Limit until predicate is truepublic final boolean allMatch(java.util.function.Predicate<? super T> c)
assertThat(of(1,2,3,4,5).allMatch(it-> it>0 && it <6),equalTo(true));
public final boolean anyMatch(java.util.function.Predicate<? super T> c)
assertThat(of(1,2,3,4,5).anyMatch(it-> it.equals(3)),equalTo(true));
public boolean xMatch(int num,
java.util.function.Predicate<? super T> c)
assertTrue(SequenceM.of(1,2,3,5,6,7).xMatch(3, i-> i>4 ));
public final boolean noneMatch(java.util.function.Predicate<? super T> c)
public final java.lang.String join()
assertEquals("123".length(),of(1, 2, 3).join().length());
public final java.lang.String join(java.lang.String sep)
assertEquals("1, 2, 3".length(), of(1, 2, 3).join(", ").length());
public final 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());
public final <U extends java.lang.Comparable<? super U>> java.util.Optional<T> minBy(java.util.function.Function<? super T,? extends U> function)
public final <C extends java.lang.Comparable<? super C>> java.util.Optional<T> maxBy(java.util.function.Function<? super T,? extends C> f)
public final HeadAndTail<T> headAndTail()
SequenceM<String> helloWorld = SequenceM.of("hello","world","last");
HeadAndTail<String> headAndTail = helloWorld.headAndTail();
String head = headAndTail.head();
assertThat(head,equalTo("hello"));
SequenceM<String> tail = headAndTail.tail();
assertThat(tail.headAndTail().head(),equalTo("world"));
headAndTail in interface SequenceM<T>public final java.util.Optional<HeadAndTail<T>> headAndTailOptional()
SequenceM<String> helloWorld = SequenceM.of();
Optional<HeadAndTail<String>> headAndTail = helloWorld.headAndTailOptional();
assertTrue(!headAndTail.isPresent());
headAndTailOptional in interface SequenceM<T>public final java.util.Optional<T> findFirst()
public final java.util.Optional<T> findAny()
public final <R> R mapReduce(Monoid<R> reducer)
public final <R> R mapReduce(java.util.function.Function<? super T,? extends R> mapper, Monoid<R> reducer)
public final <R,A> R collect(java.util.stream.Collector<? super T,A,R> collector)
collect in interface SequenceM<T>collect in interface SequenceMCollectable<T>collect in interface java.util.stream.Stream<T>collect in interface org.jooq.lambda.Collectable<T>collector - Collection operation definitionpublic final <R> R collect(java.util.function.Supplier<R> supplier,
java.util.function.BiConsumer<R,? super T> accumulator,
java.util.function.BiConsumer<R,R> combiner)
collect in interface java.util.stream.Stream<T>public final java.util.List collect(java.util.stream.Stream<java.util.stream.Collector> collectors)
List result =SequenceM.of(1,2,3).collect(Stream.of(Collectors.toList(),
Collectors.summingInt(Integer::intValue),
Collectors.averagingInt(Integer::intValue)));
assertThat(result.get(0),equalTo(Arrays.asList(1,2,3)));
assertThat(result.get(1),equalTo(6));
assertThat(result.get(2),equalTo(2.0));
collectors - Stream of Collectors to applypublic <R> java.util.List<R> collectIterable(java.lang.Iterable<java.util.stream.Collector> collectors)
List result = SequenceM.of(1,2,3).collect(
Arrays.asList(Collectors.toList(),
Collectors.summingInt(Integer::intValue),
Collectors.averagingInt(Integer::intValue)));
assertThat(result.get(0),equalTo(Arrays.asList(1,2,3)));
assertThat(result.get(1),equalTo(6));
assertThat(result.get(2),equalTo(2.0));
collectIterable in interface SequenceM<T>stream - Stream to collectcollectors - Collectors to applypublic final T reduce(Monoid<T> reducer)
SequenceM
SequenceM.of("hello","2","world","4").reduce(Reducers.toString(","));
//hello,2,world,4
public final <U> U reduce(U identity,
java.util.function.BiFunction<U,? super T,U> accumulator,
java.util.function.BinaryOperator<U> combiner)
public final java.util.List<T> reduce(java.util.stream.Stream<? extends Monoid<T>> reducers)
public final java.util.List<T> reduce(java.lang.Iterable<Monoid<T>> reducers)
public final T foldLeft(Monoid<T> reducer)
SequenceM
SequenceM.of("a","b","c").foldLeft(Reducers.toString(""));
// "abc"
public final T foldLeft(T identity, java.util.function.BinaryOperator<T> accumulator)
assertTrue(SequenceM.of("a", "b", "c").foldLeft("", String::concat).equals("abc"));
public final <T> T foldLeftMapToType(Monoid<T> reducer)
foldLeftMapToType in interface Foldable<T>foldLeftMapToType in interface SequenceM<T>reducer - Monoid to reduce valuespublic final T foldRight(Monoid<T> reducer)
SequenceM
SequenceM.of("a","b","c").foldRight(Reducers.toString(""));
// "cab"
public final <U> U foldRight(U seed,
java.util.function.BiFunction<? super T,U,U> function)
assertTrue(SequenceM.of("a","b","c").foldRight("", String::concat).equals("cba"));
foldRight in interface org.jooq.lambda.Seq<T>identity - accumulator - public final <T> T foldRightMapToType(Monoid<T> reducer)
foldRightMapToType in interface Foldable<T>foldRightMapToType in interface SequenceM<T>reducer - Monoid to reduce valuespublic final Streamable<T> toStreamable()
SequenceM
Streamable<Integer> repeat = SequenceM.of(1,2,3,4,5,6)
.map(i->i*2)
.toStreamable();
repeat.sequenceM().toList(); //Arrays.asList(2,4,6,8,10,12));
repeat.sequenceM().toList() //Arrays.asList(2,4,6,8,10,12));
toStreamable in interface SequenceM<T>public final java.util.Set<T> toSet()
public final java.util.List<T> toList()
public final <C extends java.util.Collection<T>> C toCollection(java.util.function.Supplier<C> collectionFactory)
toCollection in interface SequenceM<T>toCollection in interface SequenceMCollectable<T>toCollection in interface org.jooq.lambda.Collectable<T>public final <T> java.util.stream.Stream<T> toStream()
SequenceMpublic final SequenceM<T> stream()
public final boolean startsWith(java.lang.Iterable<T> iterable)
assertTrue(StreamUtils.sequenceM(Stream.of(1,2,3,4)).startsWith(Arrays.asList(1,2,3)));
startsWith in interface SequenceM<T>iterable - public final boolean startsWith(java.util.Iterator<T> iterator)
assertTrue(StreamUtils.sequenceM(Stream.of(1,2,3,4)).startsWith(Arrays.asList(1,2,3).iterator())) startsWith in interface SequenceM<T>iterator - public final <R> SequenceM<R> flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> fn)
assertThat(this.<Integer>of(1,2).flatMap(i -> asList(i, -i).stream()).toList(),equalTo(asList(1, -1, 2, -2)));
public final <R> SequenceM<R> flatMapAnyM(java.util.function.Function<? super T,AnyM<? extends R>> fn)
assertThat(anyM(Seq.of(1,2,3)).asSequence().flatMapAnyM(i-> anyM(CompletableFuture.completedFuture(i+2))).toList(),equalTo(Arrays.asList(3,4,5)));
flatMapAnyM in interface SequenceM<T>fn - to be appliedpublic final <R> SequenceM<R> flatMapCollection(java.util.function.Function<? super T,java.util.Collection<? extends R>> fn)
AnyM<Integer> opt = anyM(Optional.of(20));
Optional<List<Integer>> optionalList = opt.flatMap( i -> anyM(Stream.of(1,2,i))).unwrap();
//Optional [1,2,20]
In such cases using Arrays.asList would be more performant
AnyM<Integer> opt = anyM(Optional.of(20));
Optional<List<Integer>> optionalList = opt.flatMapCollection( i -> asList(1,2,i))).unwrap();
//Optional [1,2,20]
flatMapCollection in interface SequenceM<T>fn - public final <R> SequenceM<R> flatMapStream(java.util.function.Function<? super T,java.util.stream.BaseStream<? extends R,?>> fn)
assertThat(anyM(Stream.of(1,2,3)).asSequence().flatMapStream(i->Stream.of(i)).toList(),equalTo(Arrays.asList(1,2,3)));
flatMapStream in interface SequenceM<T>fn - to be appliedpublic final <R> SequenceM<R> flatMapOptional(java.util.function.Function<? super T,java.util.Optional<? extends R>> fn)
assertThat(SequenceM.of(1,2,3,null).flatMapOptional(Optional::ofNullable)
.collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,3)));
flatMapOptional in interface SequenceM<T>fn - public final <R> SequenceM<R> flatMapCompletableFuture(java.util.function.Function<? super T,java.util.concurrent.CompletableFuture<? extends R>> fn)
assertThat(SequenceM.of(1,2,3).flatMapCompletableFuture(i->CompletableFuture.completedFuture(i+2))
.collect(Collectors.toList()),
equalTo(Arrays.asList(3,4,5)));
flatMapCompletableFuture in interface SequenceM<T>fn - public final SequenceM<java.lang.Character> flatMapCharSequence(java.util.function.Function<? super T,java.lang.CharSequence> fn)
List<Character> result = anyM("input.file")
.asSequence()
.flatMapCharSequence(i->"hello world")
.toList();
assertThat(result,equalTo(Arrays.asList('h','e','l','l','o',' ','w','o','r','l','d')));
flatMapCharSequence in interface SequenceM<T>fn - public final SequenceM<java.lang.String> flatMapFile(java.util.function.Function<? super T,java.io.File> fn)
List<String> result = anyM("input.file")
.asSequence()
.map(getClass().getClassLoader()::getResource)
.peek(System.out::println)
.map(URL::getFile)
.liftAndBindFile(File::new)
.toList();
assertThat(result,equalTo(Arrays.asList("hello","world")));
flatMapFile in interface SequenceM<T>fn - public final SequenceM<java.lang.String> flatMapURL(java.util.function.Function<? super T,java.net.URL> fn)
List<String> result = anyM("input.file")
.asSequence()
.liftAndBindURL(getClass().getClassLoader()::getResource)
.toList();
assertThat(result,equalTo(Arrays.asList("hello","world")));
flatMapURL in interface SequenceM<T>fn - public final SequenceM<java.lang.String> flatMapBufferedReader(java.util.function.Function<? super T,java.io.BufferedReader> fn)
Listresult = anyM("input.file") .asSequence() .map(getClass().getClassLoader()::getResourceAsStream) .map(InputStreamReader::new) .liftAndBindBufferedReader(BufferedReader::new) .toList(); assertThat(result,equalTo(Arrays.asList("hello","world")));
flatMapBufferedReader in interface SequenceM<T>fn - public void forEach(java.util.function.Consumer<? super T> action)
public java.util.Iterator<T> iterator()
public java.util.Spliterator<T> spliterator()
public boolean isParallel()
public java.util.stream.IntStream mapToInt(java.util.function.ToIntFunction<? super T> mapper)
public java.util.stream.LongStream mapToLong(java.util.function.ToLongFunction<? super T> mapper)
public java.util.stream.DoubleStream mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper)
public java.util.stream.IntStream flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper)
public java.util.stream.LongStream flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper)
public java.util.stream.DoubleStream flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper)
public void forEachOrdered(java.util.function.Consumer<? super T> action)
forEachOrdered in interface java.util.stream.Stream<T>public java.lang.Object[] toArray()
toArray in interface java.util.stream.Stream<T>public <A> A[] toArray(java.util.function.IntFunction<A[]> generator)
toArray in interface java.util.stream.Stream<T>public long count()
public SequenceM<T> intersperse(T value)
intersperse in interface SequenceM<T>intersperse in interface org.jooq.lambda.Seq<T>public <U> SequenceM<U> ofType(java.lang.Class<U> type)
public <U> SequenceM<U> cast(java.lang.Class<U> type)
ClassCastException.
// ClassCastException SequenceM.of(1, "a", 2, "b", 3).cast(Integer.class)public java.util.Collection<T> toLazyCollection()
Collection<Integer> col = SequenceM.of(1,2,3,4,5)
.peek(System.out::println)
.toLazyCollection();
System.out.println("first!");
col.forEach(System.out::println);
//Will print out "first!" before anything else
toLazyCollection in interface SequenceM<T>public java.util.Collection<T> toConcurrentLazyCollection()
Collection<Integer> col = SequenceM.of(1,2,3,4,5)
.peek(System.out::println)
.toConcurrentLazyCollection();
System.out.println("first!");
col.forEach(System.out::println);
//Will print out "first!" before anything else
toConcurrentLazyCollection in interface SequenceM<T>public Streamable<T> toLazyStreamable()
public Streamable<T> toConcurrentLazyStreamable()
SequenceM
{
@code
Streamable<Integer> repeat = SequenceM.of(1, 2, 3, 4, 5, 6).map(i -> i + 2).toConcurrentLazyStreamable();
assertThat(repeat.sequenceM().toList(), equalTo(Arrays.asList(2, 4, 6, 8, 10, 12)));
assertThat(repeat.sequenceM().toList(), equalTo(Arrays.asList(2, 4, 6, 8, 10, 12)));
}
toConcurrentLazyStreamable in interface SequenceM<T>public void close()
public SequenceM<T> appendStream(java.util.stream.Stream<T> stream)
List<String> result = of(1,2,3).appendStream(of(100,200,300))
.map(it ->it+"!!")
.collect(Collectors.toList());
assertThat(result,equalTo(Arrays.asList("1!!","2!!","3!!","100!!","200!!","300!!")));
appendStream in interface SequenceM<T>stream - to appendpublic SequenceM<T> prependStream(java.util.stream.Stream<T> stream)
List<String> result = of(1,2,3).prependStream(of(100,200,300))
.map(it ->it+"!!").collect(Collectors.toList());
assertThat(result,equalTo(Arrays.asList("100!!","200!!","300!!","1!!","2!!","3!!")));
prependStream in interface SequenceM<T>stream - to Prependpublic SequenceM<T> append(T... values)
List<String> result = of(1,2,3).append(100,200,300)
.map(it ->it+"!!")
.collect(Collectors.toList());
assertThat(result,equalTo(Arrays.asList("1!!","2!!","3!!","100!!","200!!","300!!")));
public SequenceM<T> prepend(T... values)
List<String> result = of(1,2,3).prepend(100,200,300)
.map(it ->it+"!!").collect(Collectors.toList());
assertThat(result,equalTo(Arrays.asList("100!!","200!!","300!!","1!!","2!!","3!!")));
public SequenceM<T> insertAt(int pos, T... values)
List<String> result = of(1,2,3).insertAt(1,100,200,300)
.map(it ->it+"!!").collect(Collectors.toList());
assertThat(result,equalTo(Arrays.asList("1!!","100!!","200!!","300!!","2!!","3!!")));
public SequenceM<T> deleteBetween(int start, int end)
List<String> result = of(1,2,3,4,5,6).deleteBetween(2,4)
.map(it ->it+"!!").collect(Collectors.toList());
assertThat(result,equalTo(Arrays.asList("1!!","2!!","5!!","6!!")));
deleteBetween in interface SequenceM<T>start - indexend - indexpublic SequenceM<T> insertStreamAt(int pos, java.util.stream.Stream<T> stream)
List<String> result = of(1,2,3).insertStreamAt(1,of(100,200,300))
.map(it ->it+"!!").collect(Collectors.toList());
assertThat(result,equalTo(Arrays.asList("1!!","100!!","200!!","300!!","2!!","3!!")));
insertStreamAt in interface SequenceM<T>pos - to insert Stream atstream - to insertpublic FutureOperations<T> futureOperations(java.util.concurrent.Executor exec)
SequenceMfutureOperations in interface SequenceM<T>exec - Executor to use for Stream executionpublic boolean endsWith(java.lang.Iterable<T> iterable)
SequenceM
assertTrue(SequenceM.of(1,2,3,4,5,6)
.endsWith(Arrays.asList(5,6)));
public HotStream<T> hotStream(java.util.concurrent.Executor e)
SequenceMSequenceM.primedHotStream(Executor).
The generated HotStream is not pausable, for a pausable HotStream @see SequenceM.pausableHotStream(Executor).
Turns this SequenceM into a HotStream, a connectable Stream, being
executed on a thread on the supplied executor, that is producing data
HotStream<Integer> ints = SequenceM.range(0,Integer.MAX_VALUE)
.hotStream(exec)
ints.connect().forEach(System.out::println);
//print out all the ints
//multiple consumers are possible, so other Streams can connect on different Threads
public T firstValue()
SequenceM
assertThat(SequenceM.of(1,2,3,4)
.map(u->{throw new RuntimeException();})
.recover(e->"hello")
.firstValue(),equalTo("hello"));
firstValue in interface SequenceM<T>public void subscribe(org.reactivestreams.Subscriber<? super T> s)
subscribe in interface org.reactivestreams.Publisher<T>public <U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> zip(org.jooq.lambda.Seq<U> other)
SequenceM
{
@code
List<Tuple2<Integer, String>> list = of(1, 2).zip(of("a", "b", "c", "d")).toList();
// [[1,"a"],[2,"b"]]
}
public <S,R> SequenceM<R> zipAnyM(AnyM<? extends S> second, java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
SequenceM
{
@code
Stream<List<Integer>> zipped = anyM(Stream.of(1, 2, 3)).asSequence().zip(anyM(Optional.of(2)), (a, b) -> Arrays.asList(a, b)).toStream();
List<Integer> zip = zipped.collect(Collectors.toList()).get(0);
assertThat(zip.get(0), equalTo(1));
assertThat(zip.get(1), equalTo(2));
}
public SequenceM<T> onEmptyGet(java.util.function.Supplier<T> supplier)
onEmptyGet in interface SequenceM<T>onEmptyGet in interface org.jooq.lambda.Seq<T>public <X extends java.lang.Throwable> SequenceM<T> onEmptyThrow(java.util.function.Supplier<X> supplier)
onEmptyThrow in interface SequenceM<T>onEmptyThrow in interface org.jooq.lambda.Seq<T>public <U> SequenceM<T> distinct(java.util.function.Function<? super T,? extends U> keyExtractor)
public <U,R> SequenceM<R> zip(org.jooq.lambda.Seq<U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
public <U extends java.lang.Comparable<? super U>> SequenceM<T> sorted(java.util.function.Function<? super T,? extends U> function)
public <U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> zipStream(java.util.stream.Stream<U> other)
SequenceM
{
@code
List<Tuple2<Integer, String>> list = of(1, 2).zip(of("a", "b", "c", "d")).toList();
// [[1,"a"],[2,"b"]]
}
public SequenceM<T> xPer(int x, long time, java.util.concurrent.TimeUnit t)
SequenceM
{
@code
SimpleTimer timer = new SimpleTimer();
assertThat(SequenceM.of(1, 2, 3, 4, 5, 6).xPer(6, 100000000, TimeUnit.NANOSECONDS).collect(Collectors.toList()).size(), is(6));
}
public SequenceM<T> onePer(long time, java.util.concurrent.TimeUnit t)
SequenceM
SequenceM.iterate("", last -> "next")
.limit(100)
.batchBySize(10)
.onePer(1, TimeUnit.MICROSECONDS)
.peek(batch -> System.out.println("batched : " + batch))
.flatMap(Collection::stream)
.peek(individual -> System.out.println("Flattened : "
+ individual))
.forEach(a->{});
public SequenceM<T> debounce(long time, java.util.concurrent.TimeUnit t)
SequenceM
SequenceM.of(1,2,3,4,5,6)
.debounce(1000,TimeUnit.SECONDS).toList();
// 1
public SequenceM<java.util.List<T>> batchBySizeAndTime(int size, long time, java.util.concurrent.TimeUnit t)
SequenceM
SequenceM.of(1,2,3,4,5,6)
.batchBySizeAndTime(3,10,TimeUnit.SECONDS)
.toList();
//[[1,2,3],[4,5,6]]
batchBySizeAndTime in interface SequenceM<T>size - Max size of a batchtime - (Max) time period to build a single batch int - time unit for batchpublic SequenceM<java.util.List<T>> batchByTime(long time, java.util.concurrent.TimeUnit t)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5,6).batchByTime(1,TimeUnit.SECONDS).collect(Collectors.toList()).size(),is(1));
assertThat(SequenceM.of(1,2,3,4,5,6).batchByTime(1,TimeUnit.NANOSECONDS).collect(Collectors.toList()).size(),greaterThan(5));
batchByTime in interface SequenceM<T>time - - time period to build a single batch int - time unit for batchpublic T foldRight(T identity, java.util.function.BinaryOperator<T> accumulator)
SequenceM
assertTrue(SequenceM.of("a","b","c").foldRight("", String::concat).equals("cba"));
public boolean endsWith(java.util.stream.Stream<T> iterable)
SequenceM
assertTrue(SequenceM.of(1,2,3,4,5,6)
.endsWith(Stream.of(5,6)));
public SequenceM<T> skip(long time, java.util.concurrent.TimeUnit unit)
SequenceM
{
@code
List<Integer> result = SequenceM.of(1, 2, 3, 4, 5, 6).peek(i -> sleep(i * 100)).skip(1000, TimeUnit.MILLISECONDS).toList();
// [4,5,6]
}
public SequenceM<T> limit(long time, java.util.concurrent.TimeUnit unit)
SequenceM
{
@code
List<Integer> result = SequenceM.of(1, 2, 3, 4, 5, 6).peek(i -> sleep(i * 100)).limit(1000, TimeUnit.MILLISECONDS).toList();
// [1,2,3,4]
}
public SequenceM<java.util.List<T>> batchBySize(int size)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchBySize(3)
.collect(Collectors.toList())
.size(),is(2));
batchBySize in interface SequenceM<T>size - of batchpublic SequenceM<T> fixedDelay(long l, java.util.concurrent.TimeUnit unit)
SequenceM
{
@code
SimpleTimer timer = new SimpleTimer();
assertThat(SequenceM.of(1, 2, 3, 4, 5, 6).fixedDelay(10000, TimeUnit.NANOSECONDS).collect(Collectors.toList()).size(), is(6));
assertThat(timer.getElapsedNanoseconds(), greaterThan(60000l));
}
fixedDelay in interface SequenceM<T>l - time length in nanos of the delayunit - for the delaypublic SequenceM<T> jitter(long l)
SequenceM
{
@code
SimpleTimer timer = new SimpleTimer();
assertThat(SequenceM.of(1, 2, 3, 4, 5, 6).jitter(10000).collect(Collectors.toList()).size(), is(6));
assertThat(timer.getElapsedNanoseconds(), greaterThan(20000l));
}
public SequenceM<Streamable<T>> windowBySizeAndTime(int size, long time, java.util.concurrent.TimeUnit t)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5,6)
.windowBySizeAndTime(3,10,TimeUnit.SECONDS)
.toList()
.get(0)
.stream()
.count(),is(3l));
windowBySizeAndTime in interface SequenceM<T>size - of windowtime - of windowt - of windowpublic SequenceM<Streamable<T>> windowWhile(java.util.function.Predicate<? super T> predicate)
SequenceM
SequenceM.of(1,2,3,4,5,6)
.windowWhile(i->i%3!=0)
.forEach(System.out::println);
StreamableImpl(streamable=[1, 2, 3])
StreamableImpl(streamable=[4, 5, 6])
windowWhile in interface SequenceM<T>predicate - Window while truepublic SequenceM<Streamable<T>> windowUntil(java.util.function.Predicate<? super T> predicate)
SequenceM
SequenceM.of(1,2,3,4,5,6)
.windowUntil(i->i%3==0)
.forEach(System.out::println);
StreamableImpl(streamable=[1, 2, 3])
StreamableImpl(streamable=[4, 5, 6])
windowUntil in interface SequenceM<T>predicate - Window until truepublic SequenceM<Streamable<T>> windowStatefullyWhile(java.util.function.BiPredicate<Streamable<? super T>,? super T> predicate)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5,6)
.windowStatefullyWhile((s,i)->s.sequenceM().toList().contains(4) ? true : false)
.toList().size(),equalTo(5));
windowStatefullyWhile in interface SequenceM<T>predicate - Window while truepublic SequenceM<Streamable<T>> windowByTime(long time, java.util.concurrent.TimeUnit t)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5, 6)
.map(n-> n==6? sleep(1) : n)
.windowByTime(10,TimeUnit.MICROSECONDS)
.toList()
.get(0).sequenceM().toList()
,not(hasItem(6)));
windowByTime in interface SequenceM<T>time - max time per windowt - time unit per windowpublic SequenceM<java.util.List<T>> batchUntil(java.util.function.Predicate<? super T> predicate)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchUntil(i->i%3==0)
.toList()
.size(),equalTo(2));
batchUntil in interface SequenceM<T>predicate - Batch until predicate holds, then open next batchpublic SequenceM<java.util.List<T>> batchWhile(java.util.function.Predicate<? super T> predicate)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchWhile(i->i%3!=0)
.toList().size(),equalTo(2));
batchWhile in interface SequenceM<T>predicate - Batch while predicate holds, then open next batchpublic java.util.List collectStream(java.util.stream.Stream<java.util.stream.Collector> collectors)
SequenceM
{
@code
List result = SequenceM.of(1, 2, 3).collect(
Stream.of(Collectors.toList(), Collectors.summingInt(Integer::intValue), Collectors.averagingInt(Integer::intValue)));
assertThat(result.get(0), equalTo(Arrays.asList(1, 2, 3)));
assertThat(result.get(1), equalTo(6));
assertThat(result.get(2), equalTo(2.0));
}
collectStream in interface SequenceM<T>collectors - Stream of Collectors to applypublic <C extends java.util.Collection<? super T>> SequenceM<C> batchWhile(java.util.function.Predicate<? super T> predicate, java.util.function.Supplier<C> factory)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchWhile(i->i%3!=0)
.toList()
.size(),equalTo(2));
batchWhile in interface SequenceM<T>predicate - Batch while predicate holds, then open next batchfactory - Collection factorypublic <C extends java.util.Collection<? super T>> SequenceM<C> batchUntil(java.util.function.Predicate<? super T> predicate, java.util.function.Supplier<C> factory)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchUntil(i->i%3!=0)
.toList()
.size(),equalTo(2));
batchUntil in interface SequenceM<T>predicate - Batch until predicate holds, then open next batchfactory - Collection factorypublic <C extends java.util.Collection<? super T>> SequenceM<C> batchBySizeAndTime(int size, long time, java.util.concurrent.TimeUnit unit, java.util.function.Supplier<C> factory)
SequenceM
{
@code
List<ArrayList<Integer>> list = of(1, 2, 3, 4, 5, 6).batchBySizeAndTime(10, 1, TimeUnit.MICROSECONDS, () -> new ArrayList<>()).toList();
}
batchBySizeAndTime in interface SequenceM<T>size - Max size of a batchtime - (Max) time period to build a single batch inunit - time unit for batchfactory - Collection factorypublic <C extends java.util.Collection<T>> SequenceM<C> batchByTime(long time, java.util.concurrent.TimeUnit unit, java.util.function.Supplier<C> factory)
SequenceM
assertThat(SequenceM.of(1,1,1,1,1,1)
.batchByTime(1500,TimeUnit.MICROSECONDS,()-> new TreeSet<>())
.toList()
.get(0)
.size(),is(1));
batchByTime in interface SequenceM<T>time - - time period to build a single batch inunit - time unit for batchfactory - Collection factorypublic <C extends java.util.Collection<T>> SequenceM<C> batchBySize(int size, java.util.function.Supplier<C> factory)
SequenceM
assertThat(SequenceM.of(1,1,1,1,1,1)
.batchBySize(3,()->new TreeSet<>())
.toList()
.get(0)
.size(),is(1));
batchBySize in interface SequenceM<T>size - batch sizefactory - Collection factorypublic SequenceM<T> skipLast(int num)
SequenceMpublic SequenceM<T> limitLast(int num)
SequenceM
assertThat(SequenceM.of(1,2,3,4,5)
.limitLast(2)
.collect(Collectors.toList()),equalTo(Arrays.asList(4,5)));
public SequenceM<T> recover(java.util.function.Function<java.lang.Throwable,? extends T> fn)
SequenceM
assertThat(SequenceM.of(1,2,3,4)
.map(i->i+2)
.map(u->{throw new RuntimeException();})
.recover(e->"hello")
.firstValue(),equalTo("hello"));
public <EX extends java.lang.Throwable> SequenceM<T> recover(java.lang.Class<EX> exceptionClass, java.util.function.Function<EX,? extends T> fn)
SequenceM
assertThat(SequenceM.of(1,2,3,4)
.map(i->i+2)
.map(u->{ExceptionSoftener.throwSoftenedException( new IOException()); return null;})
.recover(IOException.class,e->"hello")
.firstValue(),equalTo("hello"));
public <R1,R2,R> SequenceM<R> forEach3(java.util.function.Function<? super T,? extends java.util.stream.BaseStream<R1,?>> stream1, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends java.util.stream.BaseStream<R2,?>>> stream2, java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,? extends R>>> yieldingFunction)
SequenceM.of(1,2)
.forEach3(a->IntStream.range(10,13),
.a->b->Stream.of(""+(a+b),"hello world"),
a->b->c->c+":"a+":"+b);
//SequenceM[11:1:2,hello world:1:2,14:1:4,hello world:1:4,12:1:2,hello world:1:2,15:1:5,hello world:1:5]
forEach3 in interface SequenceM<T>stream1 - Nested Stream to iterate overstream2 - Nested Stream to iterate overyieldingFunction - Function with pointers to the current element from both Streams that generates the new elementspublic <R1,R2,R> SequenceM<R> forEach3(java.util.function.Function<? super T,? extends java.util.stream.BaseStream<R1,?>> stream1, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends java.util.stream.BaseStream<R2,?>>> stream2, java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,java.lang.Boolean>>> filterFunction, java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,? extends R>>> yieldingFunction)
forEach3 in interface SequenceM<T>stream1 - Nested Stream to iterate overstream2 - Nested Stream to iterate overfilterFunction - Filter to apply over elements before passing non-filtered values to the yielding functionyieldingFunction - Function with pointers to the current element from both Streams that generates the new elementspublic <R1,R> SequenceM<R> forEach2(java.util.function.Function<? super T,? extends java.util.stream.BaseStream<R1,?>> stream1, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction)
SequenceM.of(1,2,3)
.forEach2(a->IntStream.range(10,13),
a->b->a+b);
/SequenceM[11,14,12,15,13,16]
public <R1,R> SequenceM<R> forEach2(java.util.function.Function<? super T,? extends java.util.stream.BaseStream<R1,?>> stream1, java.util.function.Function<? super T,java.util.function.Function<? super R1,java.lang.Boolean>> filterFunction, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction)
SequenceM.of(1,2,3)
.forEach2(a->IntStream.range(10,13),
a->b-> a<3 && b>10,
a->b->a+b);
//SequenceM[14,15]
forEach2 in interface SequenceM<T>stream1 - Nested Stream to iterate overfilterFunction - Filter to apply over elements before passing non-filtered values to the yielding functionyieldingFunction - Function with pointers to the current element from both Streams that generates the new elementspublic <X extends java.lang.Throwable> org.reactivestreams.Subscription forEachX(long numberOfElements,
java.util.function.Consumer<? super T> consumer)
ReactiveStreamsTerminalOperationsforEachX in interface ReactiveStreamsTerminalOperations<T>numberOfElements - To consume from the Stream at this timeconsumer - To accept incoming events from the Streampublic <X extends java.lang.Throwable> org.reactivestreams.Subscription forEachXWithError(long numberOfElements,
java.util.function.Consumer<? super T> consumer,
java.util.function.Consumer<? super java.lang.Throwable> consumerError)
ReactiveStreamsTerminalOperationsforEachXWithError in interface ReactiveStreamsTerminalOperations<T>numberOfElements - To consume from the Stream at this timeconsumer - To accept incoming elements from the StreamconsumerError - To accept incoming processing errors from the Streampublic <X extends java.lang.Throwable> org.reactivestreams.Subscription forEachXEvents(long numberOfElements,
java.util.function.Consumer<? super T> consumer,
java.util.function.Consumer<? super java.lang.Throwable> consumerError,
java.lang.Runnable onComplete)
ReactiveStreamsTerminalOperationsforEachXEvents in interface ReactiveStreamsTerminalOperations<T>numberOfElements - To consume from the Stream at this timeconsumer - To accept incoming elements from the StreamconsumerError - To accept incoming processing errors from the StreamonComplete - To run after an onComplete eventpublic <X extends java.lang.Throwable> void forEachWithError(java.util.function.Consumer<? super T> consumerElement, java.util.function.Consumer<? super java.lang.Throwable> consumerError)
ReactiveStreamsTerminalOperationsforEachWithError in interface ReactiveStreamsTerminalOperations<T>consumerError - To accept incoming processing errors from the Streampublic <X extends java.lang.Throwable> void forEachEvent(java.util.function.Consumer<? super T> consumerElement, java.util.function.Consumer<? super java.lang.Throwable> consumerError, java.lang.Runnable onComplete)
ReactiveStreamsTerminalOperationsforEachEvent in interface ReactiveStreamsTerminalOperations<T>consumerError - To accept incoming processing errors from the StreamonComplete - To run after an onComplete eventpublic HotStream<T> primedHotStream(java.util.concurrent.Executor e)
SequenceMSequenceM.hotStream(Executor).
The generated HotStream is not pausable, for a pausable HotStream @see SequenceM.primedPausableHotStream(Executor).
HotStream<Integer> ints = SequenceM.range(0,Integer.MAX_VALUE) .hotStream(exec) ints.connect().forEach(System.out::println); //print out all the ints - starting when connect is called. //multiple consumers are possible, so other Streams can connect on different Threads
primedHotStream in interface SequenceM<T>public PausableHotStream<T> pausableHotStream(java.util.concurrent.Executor e)
SequenceMSequenceM.primedPausableHotStream(Executor).
The generated HotStream is pausable, for a unpausable HotStream (slightly faster execution) @see SequenceM.hotStream(Executor).
HotStream<Integer> ints = SequenceM.range(0,Integer.MAX_VALUE)
.hotStream(exec)
ints.connect().forEach(System.out::println);
ints.pause(); //on a separate thread pause the generating Stream
//print out all the ints
//multiple consumers are possible, so other Streams can connect on different Threads
pausableHotStream in interface SequenceM<T>e - Executor to execute this SequenceM onpublic PausableHotStream<T> primedPausableHotStream(java.util.concurrent.Executor e)
SequenceMSequenceM.pausableHotStream(Executor).
The generated HotStream is pausable, for a unpausable HotStream @see SequenceM.primedHotStream(Executor).
HotStream<Integer> ints = SequenceM.range(0,Integer.MAX_VALUE) .hotStream(exec) ints.connect().forEach(System.out::println); //print out all the ints - starting when connect is called. //multiple consumers are possible, so other Streams can connect on different Threads
primedPausableHotStream in interface SequenceM<T>public java.lang.String format()
format in interface org.jooq.lambda.Seq<T>public org.jooq.lambda.Collectable<T> collectable()
SequenceMCollectablecollectable in interface SequenceMCollectable<T>