public interface SequenceM<T> extends Unwrapable, java.util.stream.Stream<T>, org.jooq.lambda.Seq<T>, java.lang.Iterable<T>, org.reactivestreams.Publisher<T>
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> supplier)
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<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<T> predicate)
Create a SequenceM batched by List, where each batch is populated until the predicate holds
|
<C extends java.util.Collection<T>> |
batchUntil(java.util.function.Predicate<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<T> predicate)
Create a SequenceM batched by List, where each batch is populated while the predicate holds
|
<C extends java.util.Collection<T>> |
batchWhile(java.util.function.Predicate<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 . |
<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) |
<U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> |
crossJoin(java.util.stream.Stream<U> other) |
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.
|
default SequenceM<org.jooq.lambda.tuple.Tuple2<T,java.lang.Long>> |
elapsed()
SequenceM.of(1,2,3,4,5)
.elapsed()
.forEach(System.out::println);
|
default java.util.Optional<T> |
elementAt(long index)
Return the elementAt index or Optional.empty
|
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> stream)
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)
FlatMap where the result is a Collection, flattens the resultant collections into the
host SequenceM
|
<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
|
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
|
<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
|
static SequenceM<java.lang.Double> |
fromDoubleStream(java.util.stream.DoubleStream stream)
Construct a Sequence from a Stream
|
static SequenceM<java.lang.Integer> |
fromIntStream(java.util.stream.IntStream stream)
Construct a Sequence from a Stream
|
static <T> SequenceM<T> |
fromIterable(java.lang.Iterable<T> iterable)
Construct a Sequence from an Iterable
|
static <T> SequenceM<T> |
fromList(java.util.List<T> list)
Construct a Sequence from a List (prefer this method if the source is a list,
as it allows more efficient Stream reversal).
|
static SequenceM<java.lang.Long> |
fromLongStream(java.util.stream.LongStream stream)
Construct a Sequence from a Stream
|
static <T> SequenceM<T> |
fromStream(java.util.stream.Stream<T> stream)
Construct a Sequence from a Stream
|
FutureOperations<T> |
futureOperations(java.util.concurrent.Executor exec)
Access asynchronous terminal operations (each returns a Future)
|
static <T> SequenceM<T> |
generate(java.util.function.Supplier<T> s) |
default org.jooq.lambda.tuple.Tuple2<T,SequenceM<T>> |
get(long index)
Gets the element at index, and returns a Tuple containing the element (it must be present)
and a lazy copy of the Sequence for further processing.
|
<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
|
default <U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> |
innerJoin(java.util.stream.Stream<U> other,
java.util.function.BiPredicate<T,U> predicate) |
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.
|
static <T> SequenceM<T> |
iterate(T seed,
java.util.function.UnaryOperator<T> f) |
SequenceM<T> |
jitter(long maxJitterPeriodInNanos)
Introduce a random jitter / time delay between the emission of elements
|
java.lang.String |
join()
assertEquals("123".length(),SequenceM.of(1, 2, 3).join().length());
|
java.lang.String |
join(java.lang.String sep)
assertEquals("1, 2, 3".length(), SequenceM.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());
|
default <U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> |
leftOuterJoin(java.util.stream.Stream<U> other,
java.util.function.BiPredicate<T,U> predicate) |
SequenceM<T> |
limit(long num)
assertThat(SequenceM.of(4,3,6,7).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(SequenceM.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(SequenceM.of(4,3,6,7).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 Sequence to the same type as the supplied Monoid (Reducer)
Then use Monoid to reduce values
|
java.util.Optional<T> |
max(java.util.Comparator<? super T> comparator) |
<C extends java.lang.Comparable<C>> |
maxBy(java.util.function.Function<T,C> f)
Extract the maximum as determined by the supplied function
|
java.util.Optional<T> |
min(java.util.Comparator<? super T> comparator) |
<C extends java.lang.Comparable<C>> |
minBy(java.util.function.Function<T,C> f)
Extract the minimum as determined by supplied function
|
boolean |
noneMatch(java.util.function.Predicate<? super T> c) |
static <T> SequenceM<T> |
of(T... elements)
Create an efficiently reversable Sequence from the provided elements
|
<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) |
default SequenceM<T> |
onEmptySwitch(java.util.function.Supplier<java.util.stream.Stream<T>> switchTo)
If this SequenceM is empty replace it with a another Stream
|
<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
|
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
|
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.
|
static SequenceM<java.lang.Integer> |
range(int start,
int end)
Create an efficiently reversable Sequence that produces the integers between start
and end
|
<EX extends java.lang.Throwable> |
recover(java.lang.Class<EX> exceptionClass,
java.util.function.Function<EX,T> fn)
Recover from a particular exception type
|
SequenceM<T> |
recover(java.util.function.Function<java.lang.Throwable,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 streamedMonad() 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<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.
|
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) |
default <R> SequenceM<R> |
retry(java.util.function.Function<T,R> fn)
Retry a transformation if it fails.
|
SequenceM<T> |
reverse() |
static <T> SequenceM<T> |
reversedListOf(java.util.List<T> elements)
Construct a Reveresed Sequence from the provided elements
Can be reversed (again) efficiently
|
static <T> SequenceM<T> |
reversedOf(T... elements)
Construct a Reveresed Sequence from the provided elements
Can be reversed (again) efficiently
|
<U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> |
rightOuterJoin(java.util.stream.Stream<U> other,
java.util.function.BiPredicate<T,U> predicate) |
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
|
SequenceM<T> |
sequential() |
SequenceM<T> |
shuffle() |
SequenceM<T> |
shuffle(java.util.Random random) |
default T |
single()
assertThat(SequenceM.of(1).single(),equalTo(1));
|
SequenceM<T> |
skip(long num)
assertThat(SequenceM.of(4,3,6,7).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(SequenceM.of(4,3,6,7).skipUntil(i->i==6).toList(),equalTo(Arrays.asList(6,7))); |
SequenceM<T> |
skipWhile(java.util.function.Predicate<? super T> p)
assertThat(SequenceM.of(4,3,6,7).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(SequenceM.of(4,3,6,7).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
|
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(SequenceM.of(1,2,3,4).startsWith(Arrays.asList(1,2,3)));
|
boolean |
startsWith(java.util.Iterator<T> iterator)
assertTrue(SequenceM.of(1,2,3,4).startsWith(Arrays.asList(1,2,3).iterator())) |
java.util.stream.Stream<T> |
stream()
Convert this SequenceM into a Stream
|
static <T> CyclopsSubscriber<T> |
subscriber()
Create a subscriber that can listen to Reactive Streams (simple-react, RxJava
AkkaStreams, Kontraktor, QuadarStreams etc)
|
default SequenceM<org.jooq.lambda.tuple.Tuple2<T,java.lang.Long>> |
timestamp()
SequenceM.of(1,2,3,4,5)
.timestamp()
.forEach(System.out::println)
|
<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 = SequenceM.of("hello","world")
.toCompletableFuture();
assertThat(cf.join(),equalTo(Arrays.asList("hello","world")));
|
java.util.Collection<T> |
toConcurrentLazyCollection()
Lazily converts this SequenceM into a Collection.
|
Streamable<T> |
toConcurrentLazyStreamable()
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.
|
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() |
static <T,U> org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<U>> |
unzip(SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> sequence)
Unzip a zipped Stream
|
static <T1,T2,T3> org.jooq.lambda.tuple.Tuple3<SequenceM<T1>,SequenceM<T2>,SequenceM<T3>> |
unzip3(SequenceM<org.jooq.lambda.tuple.Tuple3<T1,T2,T3>> sequence)
Unzip a zipped Stream into 3
|
static <T1,T2,T3,T4> |
unzip4(SequenceM<org.jooq.lambda.tuple.Tuple4<T1,T2,T3,T4>> sequence)
Unzip a zipped Stream into 4
|
SequenceM<Streamable<T>> |
windowBySizeAndTime(int maxSize,
long maxTime,
java.util.concurrent.TimeUnit maxTimeUnit)
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<T>,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<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<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
|
<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<T,U,R> zipper) |
<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
|
cast, close, concat, count, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, crossJoin, cycle, duplicate, duplicate, empty, flatMapToDouble, flatMapToInt, flatMapToLong, foldLeft, foldLeft, foldRight, foldRight, forEach, generate, groupBy, groupBy, groupBy, groupBy, groupBy, intersperse, isEmpty, isNotEmpty, join, join, join, join, join, limit, limitUntil, limitWhile, mapToDouble, mapToInt, mapToLong, maxBy, minBy, ofType, partition, partition, reverse, scanLeft, scanRight, seq, seq, seq, seq, seq, seq, seq, seq, seq, seq, seq, shuffle, shuffle, skip, skipUntil, skipWhile, slice, splitAt, splitAt, splitAtHead, splitAtHead, spliterator, toCollection, toList, toList, toMap, toMap, toMap, toSet, toSet, toString, toString, toString, unfold, unzip, unzip, unzip, unzip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zip, zipWithIndex
<R> R unwrap()
unwrap
in interface Unwrapable
<T1> SequenceM<T1> flatten()
SequenceM.of(Arrays.asList(1,2)).flatten();
//stream of (1, 2);
// 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)));
java.util.Optional<java.util.List<T>> toOptional()
Optional<List<String>> stream = SequenceM.of("hello","world")
.toOptional();
assertThat(stream.get(),equalTo(Arrays.asList("hello","world")));
java.util.concurrent.CompletableFuture<java.util.List<T>> toCompletableFuture()
CompletableFuture<List<String>> cf = SequenceM.of("hello","world")
.toCompletableFuture();
assertThat(cf.join(),equalTo(Arrays.asList("hello","world")));
SequenceM<T> cycle(int times)
assertThat(SequenceM.of(1,2,2)
.cycle(3)
.collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,2,1,2,2,1,2,2)));
times
- Times values should be repeated within a StreamSequenceM<T> cycle()
assertEquals(asList(1, 1, 1, 1, 1,1),SequenceM.of(1).cycle().limit(6).toList());
cycle
in interface org.jooq.lambda.Seq<T>
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));
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();
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();
org.jooq.lambda.tuple.Tuple2<java.util.Optional<T>,SequenceM<T>> splitSequenceAtHead()
SequenceM.of(1,2,3).splitAtHead()
//Optional[1], SequenceM[2,3]
org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<T>> splitAt(int where)
SequenceM.of(1,2,3).splitAt(1)
//SequenceM[1], SequenceM[2,3]
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]
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]
SequenceM<T> cycle(Monoid<T> m, int times)
List<Integer> list = AsGenericMonad,asMonad(Stream.of(1,2,2))
.cycle(Reducers.toCountInt(),3)
.collect(Collectors.toList());
//is asList(3,3,3);
m
- Monoid to be used in reductiontimes
- Number of times value should be repeated<R> SequenceM<R> cycle(java.lang.Class<R> monadC, int times)
{ @code List<Optional<Integer>> list = monad(Stream.of(1, 2)).cycle(Optional.class, 2).toList(); // is asList(Optional.of(1),Optional.of(2),Optional.of(1),Optional.of(2) )); }
monadC
- class typetimes
- SequenceM<T> cycleWhile(java.util.function.Predicate<? super T> predicate)
count =0;
assertThat(SequenceM.of(1,2,2)
.cycleWhile(next -> count++<6)
.collect(Collectors.toList()),equalTo(Arrays.asList(1,2,2,1,2,2)));
predicate
- repeat while trueSequenceM<T> cycleUntil(java.util.function.Predicate<? super T> predicate)
count =0;
assertThat(SequenceM.of(1,2,2)
.cycleUntil(next -> count++>6)
.collect(Collectors.toList()),equalTo(Arrays.asList(1,2,2,1,2,2,1)));
predicate
- repeat while true<U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> zipStream(java.util.stream.Stream<U> other)
List<Tuple2<Integer, String>> list = of(1, 2).zip(of("a", "b", "c", "d")).toList();
// [[1,"a"],[2,"b"]]
<U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> zip(org.jooq.lambda.Seq<U> other)
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>
<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']]
<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"]]
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 org.jooq.lambda.Seq<T>
<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 = asMonad(Stream.of(1, 2, 3)).zip( asMonad(Optional.of(2)), (a, b) -> Arrays.asList(a, b)); // [[1,2]] }
second
- Monad to zip withzipper
- Zipping function<S,R> SequenceM<R> zipAnyM(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));
<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 = asMonad(Stream.of(1, 2, 3)).zip( Stream.of(2, 3, 4), (a, b) -> Arrays.asList(a, b)); // [[1,2][2,3][3,4]] }
second
- Stream to zip withzipper
- Zip funcitonSequenceM<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));
windowSize
- Size of sliding windowSequenceM<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));
windowSize
- number of elements in each batchincrement
- for each windowSequenceM<java.util.List<T>> grouped(int groupSize)
{ @code List<List<Integer>> list = monad(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)); }
groupSize
- Size of each Group<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());
groupBy
in interface org.jooq.lambda.Seq<T>
SequenceM<T> scanLeft(Monoid<T> monoid)
assertEquals(asList("", "a", "ab", "abc"),SequenceM.of("a", "b", "c")
.scanLeft(Reducers.toString("")).toList());
monoid
- <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));
scanLeft
in interface org.jooq.lambda.Seq<T>
SequenceM<T> scanRight(Monoid<T> monoid)
assertThat(of("a", "b", "c").scanRight(Monoid.of("", String::concat)).toList().size(),
is(asList("", "c", "bc", "abc").size()));
<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()));
scanRight
in interface org.jooq.lambda.Seq<T>
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(SequenceM.of(4,3,6,7).sorted((a,b) -> b-a).toList(),equalTo(Arrays.asList(7,6,4,3)));
SequenceM<T> skip(long num)
assertThat(SequenceM.of(4,3,6,7).skip(2).toList(),equalTo(Arrays.asList(6,7)));
SequenceM<T> skipWhile(java.util.function.Predicate<? super T> p)
assertThat(SequenceM.of(4,3,6,7).sorted().skipWhile(i->i<6).toList(),equalTo(Arrays.asList(6,7)));
skipWhile
in interface org.jooq.lambda.Seq<T>
p
- Predicate to skip while trueSequenceM<T> skipUntil(java.util.function.Predicate<? super T> p)
assertThat(SequenceM.of(4,3,6,7).skipUntil(i->i==6).toList(),equalTo(Arrays.asList(6,7)));
skipUntil
in interface org.jooq.lambda.Seq<T>
p
- Predicate to skip until trueSequenceM<T> limit(long num)
assertThat(SequenceM.of(4,3,6,7).limit(2).toList(),equalTo(Arrays.asList(4,3));
SequenceM<T> limitWhile(java.util.function.Predicate<? super T> p)
assertThat(SequenceM.of(4,3,6,7).sorted().limitWhile(i->i<6).toList(),equalTo(Arrays.asList(3,4)));
limitWhile
in interface org.jooq.lambda.Seq<T>
p
- Limit while predicate is trueSequenceM<T> limitUntil(java.util.function.Predicate<? super T> p)
assertThat(SequenceM.of(4,3,6,7).limitUntil(i->i==6).toList(),equalTo(Arrays.asList(4,3)));
limitUntil
in interface org.jooq.lambda.Seq<T>
p
- Limit until predicate is trueboolean allMatch(java.util.function.Predicate<? super T> c)
assertThat(SequenceM.of(1,2,3,4,5).allMatch(it-> it>0 && it <6),equalTo(true));
allMatch
in interface java.util.stream.Stream<T>
c
- Predicate to check if all matchboolean anyMatch(java.util.function.Predicate<? super T> c)
assertThat(SequenceM.of(1,2,3,4,5).anyMatch(it-> it.equals(3)),equalTo(true));
anyMatch
in interface java.util.stream.Stream<T>
c
- Predicate to check if any matchboolean xMatch(int num, java.util.function.Predicate<? super T> c)
assertTrue(SequenceM.of(1,2,3,5,6,7).xMatch(3, i-> i>4 ));
boolean noneMatch(java.util.function.Predicate<? super T> c)
noneMatch
in interface java.util.stream.Stream<T>
java.lang.String join()
assertEquals("123".length(),SequenceM.of(1, 2, 3).join().length());
join
in interface org.jooq.lambda.Seq<T>
java.lang.String join(java.lang.String sep)
assertEquals("1, 2, 3".length(), SequenceM.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());
<C extends java.lang.Comparable<C>> java.util.Optional<T> minBy(java.util.function.Function<T,C> f)
minBy
in interface org.jooq.lambda.Seq<T>
java.util.Optional<T> min(java.util.Comparator<? super T> comparator)
min
in interface java.util.stream.Stream<T>
<C extends java.lang.Comparable<C>> java.util.Optional<T> maxBy(java.util.function.Function<T,C> f)
maxBy
in interface org.jooq.lambda.Seq<T>
java.util.Optional<T> max(java.util.Comparator<? super T> comparator)
max
in interface java.util.stream.Stream<T>
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"));
java.util.Optional<HeadAndTail<T>> headAndTailOptional()
SequenceM<String> helloWorld = SequenceM.of();
Optional<HeadAndTail<String>> headAndTail = helloWorld.headAndTailOptional();
assertTrue(!headAndTail.isPresent());
java.util.Optional<T> findFirst()
findFirst
in interface java.util.stream.Stream<T>
SequenceM.of(1,2,3,4,5).filter(it -> it <3).findFirst().get();
//3
(deterministic)java.util.Optional<T> findAny()
findAny
in interface java.util.stream.Stream<T>
SequenceM.of(1,2,3,4,5).filter(it -> it <3).findAny().get();
//3
(non-deterministic)<R> R mapReduce(Monoid<R> reducer)
SequenceM.of("hello","2","world","4").mapReduce(Reducers.toCountInt());
//4
reducer
- Monoid to reduce values<R> R mapReduce(java.util.function.Function<? super T,? extends R> mapper, Monoid<R> reducer)
SequenceM.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 valuesjava.util.List collectStream(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 apply<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));
stream
- Stream to collectcollectors
- Collectors to applyT reduce(Monoid<T> reducer)
SequenceM.of("hello","2","world","4").reduce(Reducers.toString(","));
//hello,2,world,4
reducer
- Use supplied Monoid to reduce valuesjava.util.Optional<T> reduce(java.util.function.BinaryOperator<T> accumulator)
reduce
in interface java.util.stream.Stream<T>
T reduce(T identity, java.util.function.BinaryOperator<T> accumulator)
reduce
in interface java.util.stream.Stream<T>
<U> U reduce(U identity, java.util.function.BiFunction<U,? super T,U> accumulator, java.util.function.BinaryOperator<U> combiner)
reduce
in interface java.util.stream.Stream<T>
java.util.List<T> reduce(java.util.stream.Stream<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 = SequenceM.of(1,2,3,4)
.reduce(Arrays.asList(sum,mult).stream() );
assertThat(result,equalTo(Arrays.asList(10,24)));
reducers
- java.util.List<T> reduce(java.lang.Iterable<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 = SequenceM.of(1,2,3,4))
.reduce(Arrays.asList(sum,mult) );
assertThat(result,equalTo(Arrays.asList(10,24)));
reducers
- T foldLeft(Monoid<T> reducer)
SequenceM.of("a","b","c").foldLeft(Reducers.toString(""));
// "abc"
reducer
- Use supplied Monoid to reduce values starting via foldLeftT foldLeft(T identity, java.util.function.BinaryOperator<T> accumulator)
assertTrue(SequenceM.of("a", "b", "c").foldLeft("", String::concat).equals("abc"));
<T> T foldLeftMapToType(Monoid<T> reducer)
SequenceM.of(1,2,3).foldLeftMapToType(Reducers.toString(""));
// "123"
reducer
- Monoid to reduce valuesT foldRight(Monoid<T> reducer)
SequenceM.of("a","b","c").foldRight(Reducers.toString(""));
// "cab"
reducer
- Use supplied Monoid to reduce values starting via foldRightT foldRight(T identity, java.util.function.BinaryOperator<T> accumulator)
assertTrue(SequenceM.of("a","b","c").foldRight("", String::concat).equals("cba"));
identity
- accumulator
- <T> T foldRightMapToType(Monoid<T> reducer)
SequenceM.of(1,2,3).foldRightMapToType(Reducers.toString(""));
// "321"
reducer
- Monoid to reduce valuesStreamable<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));
java.util.Set<T> toSet()
toSet
in interface org.jooq.lambda.Seq<T>
java.util.List<T> toList()
toList
in interface org.jooq.lambda.Seq<T>
<C extends java.util.Collection<T>> C toCollection(java.util.function.Supplier<C> collectionFactory)
toCollection
in interface org.jooq.lambda.Seq<T>
<T> java.util.stream.Stream<T> toStream()
java.util.stream.Stream<T> stream()
stream
in interface org.jooq.lambda.Seq<T>
boolean startsWith(java.lang.Iterable<T> iterable)
assertTrue(SequenceM.of(1,2,3,4).startsWith(Arrays.asList(1,2,3)));
iterable
- boolean startsWith(java.util.Iterator<T> iterator)
assertTrue(SequenceM.of(1,2,3,4).startsWith(Arrays.asList(1,2,3).iterator()))
iterator
- <R> SequenceM<R> flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> fn)
assertThat(SequenceM.of(1,2)
.flatMap(i -> asList(i, -i).stream())
.toList(),equalTo(asList(1, -1, 2, -2)));
<R> SequenceM<R> flatMapAnyM(java.util.function.Function<? super T,AnyM<? extends R>> fn)
assertThat(SequenceM.of(1,2,3)).flatMapAnyM(i-> anyM(CompletableFuture.completedFuture(i+2))).toList(),equalTo(Arrays.asList(3,4,5)));
fn
- to be applied<R> SequenceM<R> flatMapCollection(java.util.function.Function<? super T,java.util.Collection<? extends R>> fn)
SequenceM.of(1,2)
.flatMap(i -> asList(i, -i))
.toList();
//1,-1,2,-2
fn
- <R> SequenceM<R> flatMapStream(java.util.function.Function<? super T,java.util.stream.BaseStream<? extends R,?>> fn)
assertThat(SequenceM.of(1,2,3)
.flatMapStream(i->IntStream.of(i))
.toList(),equalTo(Arrays.asList(1,2,3)));
fn
- to be applied<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)));
fn
- <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)));
fn
- SequenceM<java.lang.Character> flatMapCharSequence(java.util.function.Function<? super T,java.lang.CharSequence> fn)
List<Character> result = SequenceM.of("input.file")
.flatMapCharSequence(i->"hello world")
.toList();
assertThat(result,equalTo(Arrays.asList('h','e','l','l','o',' ','w','o','r','l','d')));
fn
- SequenceM<java.lang.String> flatMapFile(java.util.function.Function<? super T,java.io.File> fn)
List<String> result = SequenceM.of("input.file")
.map(getClass().getClassLoader()::getResource)
.peek(System.out::println)
.map(URL::getFile)
.flatMapFile(File::new)
.toList();
assertThat(result,equalTo(Arrays.asList("hello","world")));
fn
- SequenceM<java.lang.String> flatMapURL(java.util.function.Function<? super T,java.net.URL> fn)
List<String> result = SequenceM.of("input.file")
.flatMapURL(getClass().getClassLoader()::getResource)
.toList();
assertThat(result,equalTo(Arrays.asList("hello","world")));
fn
- SequenceM<java.lang.String> flatMapBufferedReader(java.util.function.Function<? super T,java.io.BufferedReader> fn)
Listresult = SequenceM.of("input.file") .map(getClass().getClassLoader()::getResourceAsStream) .map(InputStreamReader::new) .liftAndBindBufferedReader(BufferedReader::new) .toList(); assertThat(result,equalTo(Arrays.asList("hello","world")));
fn
- SequenceM<T> intersperse(T value)
intersperse
in interface org.jooq.lambda.Seq<T>
<U> SequenceM<U> ofType(java.lang.Class<U> type)
ofType
in interface org.jooq.lambda.Seq<T>
<U> SequenceM<U> cast(java.lang.Class<U> type)
ClassCastException
.
// ClassCastException SequenceM.of(1, "a", 2, "b", 3).cast(Integer.class)cast
in interface org.jooq.lambda.Seq<T>
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
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
Streamable<T> toConcurrentLazyStreamable()
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)));
SequenceM<T> appendStream(java.util.stream.Stream<T> stream)
List<String> result = SequenceM.of(1,2,3)
.appendStream(SequenceM.of(100,200,300))
.map(it ->it+"!!")
.collect(Collectors.toList());
assertThat(result,equalTo(Arrays.asList("1!!","2!!","3!!","100!!","200!!","300!!")));
stream
- to appendSequenceM<T> prependStream(java.util.stream.Stream<T> stream)
List<String> result = SequenceM.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!!")));
stream
- to PrependSequenceM<T> append(T... values)
List<String> result = SequenceM.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!!")));
values
- to appendSequenceM<T> prepend(T... values)
List<String> result = SequenceM.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!!")));
values
- to prependSequenceM<T> insertAt(int pos, T... values)
List<String> result = SequenceM.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!!")));
pos
- to insert data atvalues
- to insertSequenceM<T> deleteBetween(int start, int end)
List<String> result = SequenceM.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!!")));
start
- indexend
- indexSequenceM<T> insertStreamAt(int pos, java.util.stream.Stream<T> stream)
List<String> result = SequenceM.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!!")));
pos
- to insert Stream atstream
- to insertFutureOperations<T> futureOperations(java.util.concurrent.Executor exec)
exec
- Executor to use for Stream executionboolean endsWith(java.lang.Iterable<T> iterable)
assertTrue(SequenceM.of(1,2,3,4,5,6)
.endsWith(Arrays.asList(5,6)));
iterable
- Values to checkboolean endsWith(java.util.stream.Stream<T> stream)
assertTrue(SequenceM.of(1,2,3,4,5,6)
.endsWith(Stream.of(5,6)));
stream
- Values to checkSequenceM<T> skip(long time, java.util.concurrent.TimeUnit unit)
List<Integer> result = SequenceM.of(1,2,3,4,5,6)
.peek(i->sleep(i*100))
.skip(1000,TimeUnit.MILLISECONDS)
.toList();
//[4,5,6]
time
- Length of timeunit
- Time unitSequenceM<T> limit(long time, java.util.concurrent.TimeUnit unit)
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]
time
- Length of timeunit
- Time unitSequenceM<T> skipLast(int num)
num
- SequenceM<T> limitLast(int num)
assertThat(SequenceM.of(1,2,3,4,5)
.limitLast(2)
.collect(Collectors.toList()),equalTo(Arrays.asList(4,5)));
num
- of elements to return (last elements)HotStream<T> hotStream(java.util.concurrent.Executor e)
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
e
- Executor to execute this SequenceM onT firstValue()
assertThat(SequenceM.of(1,2,3,4)
.map(u->{throw new RuntimeException();})
.recover(e->"hello")
.firstValue(),equalTo("hello"));
default T single()
assertThat(SequenceM.of(1).single(),equalTo(1));
default java.util.Optional<T> elementAt(long index)
assertThat(SequenceM.of(1,2,3,4,5).elementAt(2).get(),equalTo(3));
index
- to extract element fromdefault org.jooq.lambda.tuple.Tuple2<T,SequenceM<T>> get(long index)
SequenceM.of(1,2,3,4,5).get(2).v1
//3
index
- to extract element fromdefault SequenceM<org.jooq.lambda.tuple.Tuple2<T,java.lang.Long>> elapsed()
SequenceM.of(1,2,3,4,5)
.elapsed()
.forEach(System.out::println);
default SequenceM<org.jooq.lambda.tuple.Tuple2<T,java.lang.Long>> timestamp()
SequenceM.of(1,2,3,4,5)
.timestamp()
.forEach(System.out::println)
static <T> CyclopsSubscriber<T> subscriber()
CyclopsSubscriber<Integer> sub = SequenceM.subscriber();
SequenceM.of(1,2,3).subscribe(sub);
sub.sequenceM().forEach(System.out::println);
1
2
3
static <T> SequenceM<T> of(T... elements)
static <T> SequenceM<T> reversedOf(T... elements)
elements
- To Construct sequence fromstatic <T> SequenceM<T> reversedListOf(java.util.List<T> elements)
elements
- To Construct sequence fromstatic SequenceM<java.lang.Integer> range(int start, int end)
start
- Number of range to start fromend
- Number for range to end atstatic <T> SequenceM<T> fromStream(java.util.stream.Stream<T> stream)
stream
- Stream to construct Sequence fromstatic SequenceM<java.lang.Integer> fromIntStream(java.util.stream.IntStream stream)
stream
- Stream to construct Sequence fromstatic SequenceM<java.lang.Long> fromLongStream(java.util.stream.LongStream stream)
stream
- Stream to construct Sequence fromstatic SequenceM<java.lang.Double> fromDoubleStream(java.util.stream.DoubleStream stream)
stream
- Stream to construct Sequence fromstatic <T> SequenceM<T> fromList(java.util.List<T> list)
iterable
- to construct Sequence fromstatic <T> SequenceM<T> fromIterable(java.lang.Iterable<T> iterable)
iterable
- to construct Sequence fromstatic <T> SequenceM<T> iterate(T seed, java.util.function.UnaryOperator<T> f)
static <T> SequenceM<T> generate(java.util.function.Supplier<T> s)
static <T,U> org.jooq.lambda.tuple.Tuple2<SequenceM<T>,SequenceM<U>> unzip(SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> sequence)
unzip(SequenceM.of(new Tuple2(1, "a"), new Tuple2(2, "b"), new Tuple2(3, "c")))
// SequenceM[1,2,3], SequenceM[a,b,c]
static <T1,T2,T3> org.jooq.lambda.tuple.Tuple3<SequenceM<T1>,SequenceM<T2>,SequenceM<T3>> unzip3(SequenceM<org.jooq.lambda.tuple.Tuple3<T1,T2,T3>> sequence)
unzip3(SequenceM.of(new Tuple3(1, "a", 2l), new Tuple3(2, "b", 3l), new Tuple3(3,"c", 4l)))
// SequenceM[1,2,3], SequenceM[a,b,c], SequenceM[2l,3l,4l]
static <T1,T2,T3,T4> org.jooq.lambda.tuple.Tuple4<SequenceM<T1>,SequenceM<T2>,SequenceM<T3>,SequenceM<T4>> unzip4(SequenceM<org.jooq.lambda.tuple.Tuple4<T1,T2,T3,T4>> sequence)
unzip4(SequenceM.of(new Tuple4(1, "a", 2l,'z'), new Tuple4(2, "b", 3l,'y'), new Tuple4(3,
"c", 4l,'x')));
// SequenceM[1,2,3], SequenceM[a,b,c], SequenceM[2l,3l,4l], SequenceM[z,y,x]
<U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> crossJoin(java.util.stream.Stream<U> other)
crossJoin
in interface org.jooq.lambda.Seq<T>
default <U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> innerJoin(java.util.stream.Stream<U> other, java.util.function.BiPredicate<T,U> predicate)
innerJoin
in interface org.jooq.lambda.Seq<T>
default <U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> leftOuterJoin(java.util.stream.Stream<U> other, java.util.function.BiPredicate<T,U> predicate)
leftOuterJoin
in interface org.jooq.lambda.Seq<T>
<U> SequenceM<org.jooq.lambda.tuple.Tuple2<T,U>> rightOuterJoin(java.util.stream.Stream<U> other, java.util.function.BiPredicate<T,U> predicate)
rightOuterJoin
in interface org.jooq.lambda.Seq<T>
default SequenceM<T> onEmptySwitch(java.util.function.Supplier<java.util.stream.Stream<T>> switchTo)
assertThat(SequenceM.of(4,5,6)
.onEmptySwitch(()->SequenceM.of(1,2,3))
.toList(),
equalTo(Arrays.asList(4,5,6)));
switchTo
- Supplier that will generate the alternative StreamSequenceM<T> onEmptyGet(java.util.function.Supplier<T> supplier)
onEmptyGet
in interface org.jooq.lambda.Seq<T>
<X extends java.lang.Throwable> SequenceM<T> onEmptyThrow(java.util.function.Supplier<X> supplier)
onEmptyThrow
in interface org.jooq.lambda.Seq<T>
SequenceM<T> concat(java.util.stream.Stream<T> other)
concat
in interface org.jooq.lambda.Seq<T>
<U> SequenceM<T> distinct(java.util.function.Function<? super T,? extends U> keyExtractor)
distinct
in interface org.jooq.lambda.Seq<T>
<U,R> SequenceM<R> zip(org.jooq.lambda.Seq<U> other, java.util.function.BiFunction<T,U,R> zipper)
zip
in interface org.jooq.lambda.Seq<T>
SequenceM<T> shuffle(java.util.Random random)
shuffle
in interface org.jooq.lambda.Seq<T>
SequenceM<T> slice(long from, long to)
slice
in interface org.jooq.lambda.Seq<T>
<U extends java.lang.Comparable<? super U>> SequenceM<T> sorted(java.util.function.Function<? super T,? extends U> function)
sorted
in interface org.jooq.lambda.Seq<T>
SequenceM<T> xPer(int x, long time, java.util.concurrent.TimeUnit t)
SimpleTimer timer = new SimpleTimer();
assertThat(SequenceM.of(1,2,3,4,5,6)
.xPer(6,100000000,TimeUnit.NANOSECONDS)
.collect(Collectors.toList()).size(),is(6));
x
- number of elements to emittime
- periodt
- Time unitSequenceM<T> onePer(long time, java.util.concurrent.TimeUnit t)
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->{});
time
- periodt
- Time unitSequenceM<T> debounce(long time, java.util.concurrent.TimeUnit t)
SequenceM.of(1,2,3,4,5,6)
.debounce(1000,TimeUnit.SECONDS).toList();
// 1
time
- t
- SequenceM<java.util.List<T>> batchBySizeAndTime(int size, long time, java.util.concurrent.TimeUnit t)
SequenceM.of(1,2,3,4,5,6)
.batchBySizeAndTime(3,10,TimeUnit.SECONDS)
.toList();
//[[1,2,3],[4,5,6]]
size
- Max size of a batchtime
- (Max) time period to build a single batch int
- time unit for batch<C extends java.util.Collection<T>> SequenceM<C> batchBySizeAndTime(int size, long time, java.util.concurrent.TimeUnit unit, java.util.function.Supplier<C> factory)
List<ArrayList<Integer>> list = of(1,2,3,4,5,6)
.batchBySizeAndTime(10,1,TimeUnit.MICROSECONDS,()->new ArrayList<>())
.toList();
size
- Max size of a batchtime
- (Max) time period to build a single batch inunit
- time unit for batchfactory
- Collection factorySequenceM<java.util.List<T>> batchByTime(long time, java.util.concurrent.TimeUnit t)
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));
time
- - time period to build a single batch int
- time unit for batch<C extends java.util.Collection<T>> SequenceM<C> batchByTime(long time, java.util.concurrent.TimeUnit unit, java.util.function.Supplier<C> factory)
assertThat(SequenceM.of(1,1,1,1,1,1)
.batchByTime(1500,TimeUnit.MICROSECONDS,()-> new TreeSet<>())
.toList()
.get(0)
.size(),is(1));
time
- - time period to build a single batch inunit
- time unit for batchfactory
- Collection factorySequenceM<java.util.List<T>> batchBySize(int size)
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchBySize(3)
.collect(Collectors.toList())
.size(),is(2));
size
- of batch<C extends java.util.Collection<T>> SequenceM<C> batchBySize(int size, java.util.function.Supplier<C> supplier)
assertThat(SequenceM.of(1,1,1,1,1,1)
.batchBySize(3,()->new TreeSet<>())
.toList()
.get(0)
.size(),is(1));
size
- batch sizesupplier
- Collection factorySequenceM<T> fixedDelay(long l, java.util.concurrent.TimeUnit unit)
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));
l
- time length in nanos of the delayunit
- for the delaySequenceM<T> jitter(long maxJitterPeriodInNanos)
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));
maxJitterPeriodInNanos
- - random number less than this is used for each jitterSequenceM<Streamable<T>> windowBySizeAndTime(int maxSize, long maxTime, java.util.concurrent.TimeUnit maxTimeUnit)
assertThat(SequenceM.of(1,2,3,4,5,6)
.windowBySizeAndTime(3,10,TimeUnit.SECONDS)
.toList()
.get(0)
.stream()
.count(),is(3l));
maxSize
- of windowmaxTime
- of windowmaxTimeUnit
- of windowSequenceM<Streamable<T>> windowWhile(java.util.function.Predicate<T> predicate)
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])
predicate
- Window while trueSequenceM<Streamable<T>> windowUntil(java.util.function.Predicate<T> predicate)
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])
predicate
- Window until trueSequenceM<Streamable<T>> windowStatefullyWhile(java.util.function.BiPredicate<Streamable<T>,T> predicate)
assertThat(SequenceM.of(1,2,3,4,5,6)
.windowStatefullyWhile((s,i)->s.sequenceM().toList().contains(4) ? true : false)
.toList().size(),equalTo(5));
predicate
- Window while trueSequenceM<Streamable<T>> windowByTime(long time, java.util.concurrent.TimeUnit t)
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)));
time
- max time per windowt
- time unit per windowSequenceM<java.util.List<T>> batchUntil(java.util.function.Predicate<T> predicate)
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchUntil(i->i%3==0)
.toList()
.size(),equalTo(2));
predicate
- Batch until predicate holds, then open next batchSequenceM<java.util.List<T>> batchWhile(java.util.function.Predicate<T> predicate)
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchWhile(i->i%3!=0)
.toList().size(),equalTo(2));
predicate
- Batch while predicate holds, then open next batch<C extends java.util.Collection<T>> SequenceM<C> batchWhile(java.util.function.Predicate<T> predicate, java.util.function.Supplier<C> factory)
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchWhile(i->i%3!=0)
.toList()
.size(),equalTo(2));
predicate
- Batch while predicate holds, then open next batchfactory
- Collection factory<C extends java.util.Collection<T>> SequenceM<C> batchUntil(java.util.function.Predicate<T> predicate, java.util.function.Supplier<C> factory)
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchUntil(i->i%3!=0)
.toList()
.size(),equalTo(2));
predicate
- Batch until predicate holds, then open next batchfactory
- Collection factorySequenceM<T> recover(java.util.function.Function<java.lang.Throwable,T> fn)
assertThat(SequenceM.of(1,2,3,4)
.map(i->i+2)
.map(u->{throw new RuntimeException();})
.recover(e->"hello")
.firstValue(),equalTo("hello"));
fn
- Function that accepts a Throwable and returns an alternative value<EX extends java.lang.Throwable> SequenceM<T> recover(java.lang.Class<EX> exceptionClass, java.util.function.Function<EX,T> fn)
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"));
exceptionClass
- Type to recover fromfn
- That accepts an error and returns an alternative valuedefault <R> SequenceM<R> retry(java.util.function.Function<T,R> fn)
given(serviceMock.apply(anyInt())).willThrow(
new RuntimeException(new SocketException("First")),
new RuntimeException(new IOException("Second"))).willReturn(
"42");
String result = SequenceM.of( 1, 2, 3)
.retry(serviceMock)
.firstValue();
assertThat(result, is("42"));
fn
- Function to retry if fails