public class StreamUtils
extends java.lang.Object
Constructor and Description |
---|
StreamUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.stream.Stream<T> |
append(java.util.stream.Stream<T> stream,
T... values)
Append values to the end of this SequenceM
|
static <T> java.util.stream.Stream<T> |
appendStream(java.util.stream.Stream<T> stream1,
java.util.stream.Stream<T> append)
Append Stream to this SequenceM
|
static <T> java.util.stream.Stream<ListX<T>> |
batchBySize(java.util.stream.Stream<T> stream,
int groupSize)
Group elements in a Monad into a Stream
|
static <T,C extends java.util.Collection<? super T>> |
batchBySize(java.util.stream.Stream<T> stream,
int groupSize,
java.util.function.Supplier<C> factory) |
static <T> java.util.stream.Stream<ListX<T>> |
batchBySizeAndTime(java.util.stream.Stream<T> stream,
int size,
long time,
java.util.concurrent.TimeUnit t) |
static <T,C extends java.util.Collection<? super T>> |
batchBySizeAndTime(java.util.stream.Stream<T> stream,
int size,
long time,
java.util.concurrent.TimeUnit t,
java.util.function.Supplier<C> factory) |
static <T> java.util.stream.Stream<ListX<T>> |
batchByTime(java.util.stream.Stream<T> stream,
long time,
java.util.concurrent.TimeUnit t) |
static <T,C extends java.util.Collection<? super T>> |
batchByTime(java.util.stream.Stream<T> stream,
long time,
java.util.concurrent.TimeUnit t,
java.util.function.Supplier<C> factory) |
static <T> java.util.stream.Stream<ListX<T>> |
batchUntil(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate) |
static <T> java.util.stream.Stream<ListX<T>> |
batchWhile(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate) |
static <T,C extends java.util.Collection<? super T>> |
batchWhile(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate,
java.util.function.Supplier<C> factory) |
static <T,U> java.util.stream.Stream<U> |
cast(java.util.stream.Stream<T> stream,
java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
static <T> java.util.stream.Stream<T> |
combine(java.util.stream.Stream<T> stream,
java.util.function.BiPredicate<? super T,? super T> predicate,
java.util.function.BinaryOperator<T> op) |
static <T> java.util.stream.Stream<T> |
completableFutureToStream(java.util.concurrent.CompletableFuture<T> future) |
static <U> java.util.stream.Stream<U> |
concat(java.lang.Object o,
java.util.stream.Stream<U> stream)
Concat an Object and a Stream
If the Object is a Stream, Streamable or Iterable will be converted (or left) in Stream form and concatonated
Otherwise a new Stream.of(o) is created
|
static <U> java.util.stream.Stream<U> |
cycle(int times,
Streamable<U> s)
Create a Stream that finitely cycles the provided Streamable, provided number of times
|
static <T> java.util.stream.Stream<T> |
cycle(java.util.stream.Stream<T> stream,
Monoid<T> m,
int times)
Convert to a Stream with the result of a reduction operation repeated
specified times
|
static <U> java.util.stream.Stream<U> |
cycle(java.util.stream.Stream<U> s)
Create a new Stream that infiniteable cycles the provided Stream
|
static <U> java.util.stream.Stream<U> |
cycle(Streamable<U> s)
Create a Stream that infiniteable cycles the provided Streamable
|
static <T> java.util.stream.Stream<T> |
cycleUntil(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate)
Repeat in a Stream until specified predicate holds
|
static <T> java.util.stream.Stream<T> |
cycleWhile(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate)
Repeat in a Stream while specified predicate holds
|
static <T> java.util.stream.Stream<T> |
debounce(java.util.stream.Stream<T> stream,
long time,
java.util.concurrent.TimeUnit t) |
static <T> java.util.stream.Stream<T> |
deleteBetween(java.util.stream.Stream<T> stream,
int start,
int end)
Delete elements between given indexes in a Stream
|
static <T> org.jooq.lambda.tuple.Tuple2<java.util.stream.Stream<T>,java.util.stream.Stream<T>> |
duplicate(java.util.stream.Stream<T> stream)
Duplicate a Stream, buffers intermediate values, leaders may change positions so a limit
can be safely applied to the leading stream.
|
static <T> boolean |
endsWith(java.util.stream.Stream<T> stream,
java.lang.Iterable<T> iterable) |
static <T> T |
firstValue(java.util.stream.Stream<T> stream) |
static <T> java.util.stream.Stream<T> |
fixedDelay(java.util.stream.Stream<T> stream,
long time,
java.util.concurrent.TimeUnit unit) |
static <T,R> java.util.stream.Stream<R> |
flatMapAnyM(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,AnyM<? extends R>> fn) |
static <T> java.util.stream.Stream<java.lang.String> |
flatMapBufferedReader(java.util.stream.Stream<T> stream,
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
|
static <T> java.util.stream.Stream<java.lang.Character> |
flatMapCharSequence(java.util.stream.Stream<T> stream,
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.
|
static <T,R> java.util.stream.Stream<R> |
flatMapCompletableFuture(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,java.util.concurrent.CompletableFuture<? extends R>> fn)
assertThat(StreamUtils.flatMapCompletableFuture(Stream.of(1,2,3),
i->CompletableFuture.completedFuture(i+2))
.collect(Collectors.toList()),
equalTo(Arrays.asList(3,4,5)));
|
static <T> java.util.stream.Stream<java.lang.String> |
flatMapFile(java.util.stream.Stream<T> stream,
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.
|
static <T,R> java.util.stream.Stream<R> |
flatMapIterable(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> fn)
flatMap operation that allows a Collection to be returned
|
static <T,R> java.util.stream.Stream<R> |
flatMapOptional(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,java.util.Optional<? extends R>> fn)
cross type flatMap, removes null entries
|
static <T,R> java.util.stream.Stream<R> |
flatMapSequenceM(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,ReactiveSeq<? extends R>> fn)
flatMap operation
|
static <T,R> java.util.stream.Stream<R> |
flatMapStream(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,? extends java.util.stream.BaseStream<? extends R,?>> fn)
assertThat(StreamUtils.flatMapStream(Stream.of(1,2,3),
i->Stream.of(i)).collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,3)));
|
static <T> java.util.stream.Stream<java.lang.String> |
flatMapURL(java.util.stream.Stream<T> stream,
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
|
static <T,R> ReactiveSeq<R> |
flatten(java.util.stream.Stream<T> stream) |
static <T> T |
foldLeft(java.util.stream.Stream<T> stream,
Monoid<T> reducer) |
static <T> T |
foldLeftMapToType(java.util.stream.Stream<T> stream,
Reducer<T> reducer)
Attempt to map this Monad to the same type as the supplied Monoid (using mapToType on the monoid interface)
Then use Monoid to reduce values
|
static <T> T |
foldRight(java.util.stream.Stream<T> stream,
Monoid<T> reducer) |
static <T> T |
foldRightMapToType(java.util.stream.Stream<T> stream,
Reducer<T> reducer)
Attempt to map this Monad to the same type as the supplied Monoid (using mapToType on the monoid interface)
Then use Monoid to reduce values
|
static <T,X extends java.lang.Throwable> |
forEachEvent(java.util.stream.Stream<T> stream,
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.
|
static <T,X extends java.lang.Throwable> |
forEachWithError(java.util.stream.Stream<T> stream,
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,
|
static <T,X extends java.lang.Throwable> |
forEachX(java.util.stream.Stream<T> stream,
long x,
java.util.function.Consumer<? super T> consumerElement)
Perform a forEach operation over the Stream, without closing it, consuming only the specified number of elements from
the Stream, at this time.
|
static <T,X extends java.lang.Throwable> |
forEachXEvents(java.util.stream.Stream<T> stream,
long x,
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 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.
|
static <T,X extends java.lang.Throwable> |
forEachXWithError(java.util.stream.Stream<T> stream,
long x,
java.util.function.Consumer<? super T> consumerElement,
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.
|
static <T> FutureOperations<T> |
futureOperations(java.util.stream.Stream<T> stream,
java.util.concurrent.Executor exec) |
static <T> java.util.stream.Stream<ListX<T>> |
groupedStatefullyUntil(java.util.stream.Stream<T> stream,
java.util.function.BiPredicate<ListX<? super T>,? super T> predicate) |
static <T> HeadAndTail<T> |
headAndTail(java.util.stream.Stream<T> stream)
extract head and tail together
|
static <T> HotStream<T> |
hotStream(java.util.stream.Stream<T> stream,
java.util.concurrent.Executor exec) |
static <T> java.util.stream.Stream<T> |
insertAt(java.util.stream.Stream<T> stream,
int pos,
T... values)
Insert data into a stream at given position
|
static <T> java.util.stream.Stream<T> |
insertStreamAt(java.util.stream.Stream<T> stream1,
int pos,
java.util.stream.Stream<T> insert)
Insert a Stream into the middle of this stream at the specified position
|
static <T> java.util.stream.Stream<T> |
intersperse(java.util.stream.Stream<T> stream,
T value)
Returns a stream with a given value interspersed between any two values
of this stream.
|
static <T> java.util.stream.Stream<T> |
jitter(java.util.stream.Stream<T> stream,
long jitterInNanos) |
static <T> java.lang.String |
join(java.util.stream.Stream<T> stream) |
static <T> java.lang.String |
join(java.util.stream.Stream<T> stream,
java.lang.String sep) |
static <T> java.lang.String |
join(java.util.stream.Stream<T> stream,
java.lang.String sep,
java.lang.String start,
java.lang.String end) |
static <U> java.util.stream.Stream<U> |
limit(java.util.stream.Stream<U> stream,
long time,
java.util.concurrent.TimeUnit unit) |
static <U> java.util.stream.Stream<U> |
limitLast(java.util.stream.Stream<U> stream,
int num) |
static <U> java.util.stream.Stream<U> |
limitUntil(java.util.stream.Stream<U> stream,
java.util.function.Predicate<? super U> predicate)
Take elements from a Stream until the predicate holds
|
static <U> java.util.stream.Stream<U> |
limitWhile(java.util.stream.Stream<U> stream,
java.util.function.Predicate<? super U> predicate)
Take elements from a stream while the predicates hold
|
static <T,R> R |
mapReduce(java.util.stream.Stream<T> stream,
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
|
static <T,R> R |
mapReduce(java.util.stream.Stream<T> stream,
Reducer<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
|
static <T> java.util.Optional<T> |
max(java.util.stream.Stream<T> stream,
java.util.Comparator<? super T> comparator) |
static <T,C extends java.lang.Comparable<? super C>> |
maxBy(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,? extends C> f) |
static <T> java.util.Optional<T> |
min(java.util.stream.Stream<T> stream,
java.util.Comparator<? super T> comparator) |
static <T,C extends java.lang.Comparable<? super C>> |
minBy(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,? extends C> f) |
static <T> boolean |
noneMatch(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> c)
assertThat(StreamUtils.noneMatch(of(1,2,3,4,5),it-> it==5000),equalTo(true));
|
static <T,U> java.util.stream.Stream<U> |
ofType(java.util.stream.Stream<T> stream,
java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
static <T> java.util.stream.Stream<T> |
onePer(java.util.stream.Stream<T> stream,
long time,
java.util.concurrent.TimeUnit t) |
static <T> java.util.stream.Stream<T> |
optionalToStream(java.util.Optional<T> optional) |
static <T> org.jooq.lambda.tuple.Tuple2<java.util.stream.Stream<T>,java.util.stream.Stream<T>> |
partition(java.util.stream.Stream<T> stream,
java.util.function.Predicate<T> splitter)
Partition a Stream into two one a per element basis, based on predicate's boolean value
|
static <T> PausableHotStream<T> |
pausableHotStream(java.util.stream.Stream<T> stream,
java.util.concurrent.Executor exec) |
static <T> java.util.stream.Stream<T> |
prepend(java.util.stream.Stream<T> stream,
T... values)
Prepend given values to the start of the Stream
|
static <T> java.util.stream.Stream<T> |
prependStream(java.util.stream.Stream<T> stream1,
java.util.stream.Stream<T> prepend)
Prepend Stream to this SequenceM
|
static <T> HotStream<T> |
primedHotStream(java.util.stream.Stream<T> stream,
java.util.concurrent.Executor exec) |
static <T> PausableHotStream<T> |
primedPausableHotStream(java.util.stream.Stream<T> stream,
java.util.concurrent.Executor exec) |
static <T> org.jooq.lambda.tuple.Tuple4<java.util.stream.Stream<T>,java.util.stream.Stream<T>,java.util.stream.Stream<T>,java.util.stream.Stream<T>> |
quadruplicate(java.util.stream.Stream<T> stream)
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 <T> ReactiveSeq<T> |
reactiveSeq(java.util.stream.Stream<T> stream,
java.util.Optional<ReversableSpliterator> rev) |
static <T,EX extends java.lang.Throwable> |
recover(java.util.stream.Stream<T> stream,
java.lang.Class<EX> type,
java.util.function.Function<EX,? extends T> fn) |
static <T> java.util.stream.Stream<T> |
recover(java.util.stream.Stream<T> stream,
java.util.function.Function<java.lang.Throwable,? extends T> fn) |
static <R> ListX<R> |
reduce(java.util.stream.Stream<R> stream,
java.lang.Iterable<? extends Monoid<R>> reducers)
Simultaneously reduce a stream with multiple reducers
|
static <R> ListX<R> |
reduce(java.util.stream.Stream<R> stream,
java.util.stream.Stream<? extends Monoid<R>> reducers)
Simultanously reduce a stream with multiple reducers
|
static <U> java.util.stream.Stream<U> |
reverse(java.util.stream.Stream<U> stream)
Reverse a Stream
|
static <U> java.util.stream.Stream<U> |
reversedStream(java.util.List<U> list)
Create a reversed Stream from a List
|
static <T> java.util.stream.Stream<T> |
scanLeft(java.util.stream.Stream<T> stream,
Monoid<T> monoid)
Scan left using supplied Monoid
|
static <U,T> java.util.stream.Stream<U> |
scanRight(java.util.stream.Stream<T> stream,
U identity,
java.util.function.BiFunction<? super T,? super U,? extends U> combiner) |
static <T> HotStream<T> |
schedule(java.util.stream.Stream<T> stream,
java.lang.String cron,
java.util.concurrent.ScheduledExecutorService ex)
Execute this Stream on a schedule
|
static <T> HotStream<T> |
scheduleFixedDelay(java.util.stream.Stream<T> stream,
long delay,
java.util.concurrent.ScheduledExecutorService ex)
Execute this Stream on a schedule
|
static <T> HotStream<T> |
scheduleFixedRate(java.util.stream.Stream<T> stream,
long rate,
java.util.concurrent.ScheduledExecutorService ex)
Execute this Stream on a schedule
|
static <T> Streamable<T> |
shuffle(java.util.stream.Stream<T> stream) |
static <U> java.util.stream.Stream<U> |
skip(java.util.stream.Stream<U> stream,
long time,
java.util.concurrent.TimeUnit unit) |
static <U> java.util.stream.Stream<U> |
skipLast(java.util.stream.Stream<U> stream,
int num) |
static <U> java.util.stream.Stream<U> |
skipUntil(java.util.stream.Stream<U> stream,
java.util.function.Predicate<? super U> predicate)
skip elements in Stream until Predicate holds true
|
static <U> java.util.stream.Stream<U> |
skipWhile(java.util.stream.Stream<U> stream,
java.util.function.Predicate<? super U> predicate)
skip elements in a Stream while Predicate holds true
|
static <T> java.util.stream.Stream<ListX<T>> |
sliding(java.util.stream.Stream<T> stream,
int windowSize)
Create a sliding view over this Stream
|
static <T> java.util.stream.Stream<ListX<T>> |
sliding(java.util.stream.Stream<T> stream,
int windowSize,
int increment)
Create a sliding view over this Stream
|
static <T> org.jooq.lambda.tuple.Tuple2<java.util.stream.Stream<T>,java.util.stream.Stream<T>> |
splitAt(java.util.stream.Stream<T> stream,
int where)
Split at supplied location
|
static <T> org.jooq.lambda.tuple.Tuple2<java.util.stream.Stream<T>,java.util.stream.Stream<T>> |
splitBy(java.util.stream.Stream<T> stream,
java.util.function.Predicate<T> splitter)
Split stream at point where predicate no longer holds
|
static <T> boolean |
startsWith(java.util.stream.Stream<T> stream,
java.lang.Iterable<T> iterable)
assertTrue(StreamUtils.startsWith(Stream.of(1,2,3,4),Arrays.asList(1,2,3)));
|
static <T> boolean |
startsWith(java.util.stream.Stream<T> stream,
java.util.Iterator<T> iterator)
assertTrue(StreamUtils.startsWith(Stream.of(1,2,3,4),Arrays.asList(1,2,3).iterator()))
|
static <T> boolean |
startsWith(java.util.stream.Stream<T> stream,
java.util.stream.Stream<T> stream2) |
static <U> java.util.stream.Stream<U> |
stream(java.lang.Iterable<U> it)
Create a stream from an iterable
|
static <U> java.util.stream.Stream<U> |
stream(java.util.Iterator<U> it)
Create a stream from an iterator
|
static <K,V> java.util.stream.Stream<java.util.Map.Entry<K,V>> |
stream(java.util.Map<K,V> it)
Create a stream from a map
|
static <U> java.util.stream.Stream<U> |
stream(java.util.Spliterator<U> it) |
static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> |
streamToCompletableFuture(java.util.stream.Stream<T> stream) |
static <T> java.util.Optional<ListX<T>> |
streamToOptional(java.util.stream.Stream<T> stream) |
static <A> ListX<java.util.Iterator<A>> |
toBufferingCopier(java.util.Iterator<A> iterator,
int copies) |
static <A> org.jooq.lambda.tuple.Tuple2<java.util.Iterator<A>,java.util.Iterator<A>> |
toBufferingDuplicator(java.util.Iterator<A> iterator) |
static <A> org.jooq.lambda.tuple.Tuple2<java.util.Iterator<A>,java.util.Iterator<A>> |
toBufferingDuplicator(java.util.Iterator<A> iterator,
long pos) |
static <A> CollectionX<A> |
toConcurrentLazyCollection(java.util.Iterator<A> iterator) |
static <A> CollectionX<A> |
toConcurrentLazyCollection(java.util.stream.Stream<A> stream)
Lazily constructs a Collection from specified Stream.
|
static <T> Streamable<T> |
toConcurrentLazyStreamable(java.util.stream.Stream<T> stream) |
static <A> CollectionX<A> |
toLazyCollection(java.util.Iterator<A> iterator) |
static <A> CollectionX<A> |
toLazyCollection(java.util.stream.Stream<A> stream)
Projects an immutable collection of this stream.
|
static <T> Streamable<T> |
toLazyStreamable(java.util.stream.Stream<T> stream) |
static <T> java.util.List<T> |
toList(java.util.stream.Stream<T> stream) |
static <T> java.util.Set<T> |
toSet(java.util.stream.Stream<T> stream) |
static <T> Streamable<T> |
toStreamable(java.util.stream.Stream<T> stream) |
static <T> org.jooq.lambda.tuple.Tuple3<java.util.stream.Stream<T>,java.util.stream.Stream<T>,java.util.stream.Stream<T>> |
triplicate(java.util.stream.Stream<T> stream)
Triplicates a Stream
Buffers intermediate values, leaders may change positions so a limit
can be safely applied to the leading stream.
|
static <T> java.util.stream.Stream<Streamable<T>> |
window(java.util.stream.Stream<T> stream,
int windowSize,
int increment)
Create a sliding view over this Stream
|
static <T> java.util.stream.Stream<Streamable<T>> |
windowByTime(java.util.stream.Stream<T> stream,
long time,
java.util.concurrent.TimeUnit t) |
static <T> boolean |
xMatch(java.util.stream.Stream<T> stream,
int num,
java.util.function.Predicate<? super T> c)
Check that there are specified number of matches of predicate in the Stream
|
static <T> java.util.stream.Stream<T> |
xPer(java.util.stream.Stream<T> stream,
int x,
long time,
java.util.concurrent.TimeUnit t) |
static <T,S,R> java.util.stream.Stream<R> |
zipAnyM(java.util.stream.Stream<T> stream,
AnyM<? extends S> second,
java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Generic zip function.
|
static <T,S,R> java.util.stream.Stream<R> |
zipSequence(java.util.stream.Stream<T> stream,
java.util.stream.Stream<? extends S> second,
java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Generic zip function.
|
static <T,S,R> java.util.stream.Stream<R> |
zipStream(java.util.stream.Stream<T> stream,
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
|
public static final <T> java.util.Optional<ListX<T>> streamToOptional(java.util.stream.Stream<T> stream)
public static final <T> java.util.stream.Stream<T> optionalToStream(java.util.Optional<T> optional)
public static final <T> java.util.concurrent.CompletableFuture<java.util.List<T>> streamToCompletableFuture(java.util.stream.Stream<T> stream)
public static final <T> java.util.stream.Stream<T> completableFutureToStream(java.util.concurrent.CompletableFuture<T> future)
public static <T,X extends java.lang.Throwable> org.reactivestreams.Subscription forEachX(java.util.stream.Stream<T> stream, long x, java.util.function.Consumer<? super T> consumerElement)
Stream
- - the Stream to consume data fromnumberOfElements
- To consume from the Stream at this timeconsumer
- To accept incoming events from the Streampublic static <T,X extends java.lang.Throwable> org.reactivestreams.Subscription forEachXWithError(java.util.stream.Stream<T> stream, long x, java.util.function.Consumer<? super T> consumerElement, java.util.function.Consumer<? super java.lang.Throwable> consumerError)
Stream
- - the Stream to consume data fromnumberOfElements
- 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 static <T,X extends java.lang.Throwable> org.reactivestreams.Subscription forEachXEvents(java.util.stream.Stream<T> stream, long x, java.util.function.Consumer<? super T> consumerElement, java.util.function.Consumer<? super java.lang.Throwable> consumerError, java.lang.Runnable onComplete)
Stream
- - the Stream to consume data fromnumberOfElements
- 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 static <T,X extends java.lang.Throwable> void forEachWithError(java.util.stream.Stream<T> stream, java.util.function.Consumer<? super T> consumerElement, java.util.function.Consumer<? super java.lang.Throwable> consumerError)
Stream
- - the Stream to consume data fromconsumer
- To accept incoming elements from the StreamconsumerError
- To accept incoming processing errors from the Streampublic static <T,X extends java.lang.Throwable> void forEachEvent(java.util.stream.Stream<T> stream, java.util.function.Consumer<? super T> consumerElement, java.util.function.Consumer<? super java.lang.Throwable> consumerError, java.lang.Runnable onComplete)
Stream
- - the Stream to consume data fromconsumer
- To accept incoming elements from the StreamconsumerError
- To accept incoming processing errors from the StreamonComplete
- To run after an onComplete eventpublic static <T> HotStream<T> schedule(java.util.stream.Stream<T> stream, java.lang.String cron, java.util.concurrent.ScheduledExecutorService ex)
//run at 8PM every night
StreamUtils.schedule(Stream.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
,"0 20 * * *",Executors.newScheduledThreadPool(1)));
Connect to the Scheduled Stream
HotStream<Data> dataStream = StreamUtils.schedule(Stream.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
,"0 20 * * *",Executors.newScheduledThreadPool(1)));
data.connect().forEach(this::logToDB);
stream
- the stream to schedule element processing oncron
- Expression that determines when each job will runex
- ScheduledExecutorServicepublic static <T> HotStream<T> scheduleFixedDelay(java.util.stream.Stream<T> stream, long delay, java.util.concurrent.ScheduledExecutorService ex)
//run every 60 seconds after last job completes
StreamUtils.scheduleFixedDelay(Stream.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
,60_000,Executors.newScheduledThreadPool(1)));
Connect to the Scheduled Stream
HotStream<Data> dataStream = StreamUtils.scheduleFixedDelay(Stream.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
,60_000,Executors.newScheduledThreadPool(1)));
data.connect().forEach(this::logToDB);
stream
- the stream to schedule element processing ondelay
- Between last element completes passing through the Stream until the next one startsex
- ScheduledExecutorServicepublic static <T> HotStream<T> scheduleFixedRate(java.util.stream.Stream<T> stream, long rate, java.util.concurrent.ScheduledExecutorService ex)
//run every 60 seconds
StreamUtils.scheduleFixedRate(Stream.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob),
60_000,Executors.newScheduledThreadPool(1)));
Connect to the Scheduled Stream
HotStream<Data> dataStream = StreamUtils.scheduleFixedRate(Stream.generate(()->"next job:"+formatDate(new Date()))
.map(this::processJob)
,60_000,Executors.newScheduledThreadPool(1)));
data.connect().forEach(this::logToDB);
stream
- the stream to schedule element processing onrate
- Time in millis between job runsex
- ScheduledExecutorServicepublic static final <T> org.jooq.lambda.tuple.Tuple2<java.util.stream.Stream<T>,java.util.stream.Stream<T>> splitAt(java.util.stream.Stream<T> stream, int where)
ReactiveSeq.of(1,2,3).splitAt(1)
//SequenceM[1], SequenceM[2,3]
public static final <T> org.jooq.lambda.tuple.Tuple2<java.util.stream.Stream<T>,java.util.stream.Stream<T>> splitBy(java.util.stream.Stream<T> stream, java.util.function.Predicate<T> splitter)
ReactiveSeq.of(1, 2, 3, 4, 5, 6).splitBy(i->i<4)
//SequenceM[1,2,3] SequenceM[4,5,6]
public static final <T> org.jooq.lambda.tuple.Tuple2<java.util.stream.Stream<T>,java.util.stream.Stream<T>> partition(java.util.stream.Stream<T> stream, java.util.function.Predicate<T> splitter)
ReactiveSeq.of(1, 2, 3, 4, 5, 6).partition(i -> i % 2 != 0)
//SequenceM[1,3,5], SequenceM[2,4,6]
public static final <T> org.jooq.lambda.tuple.Tuple2<java.util.stream.Stream<T>,java.util.stream.Stream<T>> duplicate(java.util.stream.Stream<T> stream)
Tuple2<ReactiveSeq<Integer>, ReactiveSeq<Integer>> copies =of(1,2,3,4,5,6).duplicate();
assertTrue(copies.v1.anyMatch(i->i==2));
assertTrue(copies.v2.anyMatch(i->i==2));
public static final <T> org.jooq.lambda.tuple.Tuple3<java.util.stream.Stream<T>,java.util.stream.Stream<T>,java.util.stream.Stream<T>> triplicate(java.util.stream.Stream<T> stream)
Tuple3<ReactiveSeq<Tuple3<T1,T2,T3>>,ReactiveSeq<Tuple3<T1,T2,T3>>,ReactiveSeq<Tuple3<T1,T2,T3>>> Tuple3 = sequence.triplicate();
public static final <T> org.jooq.lambda.tuple.Tuple4<java.util.stream.Stream<T>,java.util.stream.Stream<T>,java.util.stream.Stream<T>,java.util.stream.Stream<T>> quadruplicate(java.util.stream.Stream<T> stream)
Tuple4<ReactiveSeq<Tuple4<T1,T2,T3,T4>>,ReactiveSeq<Tuple4<T1,T2,T3,T4>>,ReactiveSeq<Tuple4<T1,T2,T3,T4>>,ReactiveSeq<Tuple4<T1,T2,T3,T4>>> quad = sequence.quadruplicate();
public static final <T> java.util.stream.Stream<T> appendStream(java.util.stream.Stream<T> stream1, java.util.stream.Stream<T> append)
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!!")));
stream
- to appendpublic static final <T> java.util.stream.Stream<T> prependStream(java.util.stream.Stream<T> stream1, java.util.stream.Stream<T> prepend)
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!!")));
stream
- to Prependpublic static final <T> java.util.stream.Stream<T> append(java.util.stream.Stream<T> stream, 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!!")));
values
- to appendpublic static final <T> java.util.stream.Stream<T> prepend(java.util.stream.Stream<T> stream, 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!!")));
values
- to prependpublic static final <T> java.util.stream.Stream<T> insertAt(java.util.stream.Stream<T> stream, 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!!")));
pos
- to insert data atvalues
- to insertpublic static final <T> java.util.stream.Stream<T> deleteBetween(java.util.stream.Stream<T> stream, int start, int end)
List<String> result = StreamUtils.deleteBetween(Stream.of(1,2,3,4,5,6),2,4)
.map(it ->it+"!!")
.collect(Collectors.toList());
assertThat(result,equalTo(Arrays.asList("1!!","2!!","5!!","6!!")));
start
- indexend
- indexpublic static final <T> java.util.stream.Stream<T> insertStreamAt(java.util.stream.Stream<T> stream1, int pos, java.util.stream.Stream<T> insert)
List<String> result = StreamUtils.insertStreamAt(Stream.of(1,2,3),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 insertpublic static final <T> java.util.stream.Stream<T> cycle(java.util.stream.Stream<T> stream, Monoid<T> m, int times)
List<Integer> list = StreamUtils.cycle(Stream.of(1,2,2),Reducers.toCountInt(),3)
.
.collect(Collectors.toList());
//is asList(3,3,3);
m
- Monoid to be used in reductiontimes
- Number of times value should be repeatedpublic static final <T> HeadAndTail<T> headAndTail(java.util.stream.Stream<T> stream)
Stream<String> helloWorld = Stream.of("hello","world","last");
HeadAndTail<String> headAndTail = StreamUtils.headAndTail(helloWorld);
String head = headAndTail.head();
assertThat(head,equalTo("hello"));
ReactiveSeq<String> tail = headAndTail.tail();
assertThat(tail.headAndTail().head(),equalTo("world"));
public static <U> java.util.stream.Stream<U> skipUntil(java.util.stream.Stream<U> stream, java.util.function.Predicate<? super U> predicate)
StreamUtils.skipUntil(Stream.of(4,3,6,7),i->i==6).collect(Collectors.toList())
// [6,7]
stream
- Stream to skip elements frompredicate
- to applypublic static <U> java.util.stream.Stream<U> skipLast(java.util.stream.Stream<U> stream, int num)
public static <U> java.util.stream.Stream<U> limitLast(java.util.stream.Stream<U> stream, int num)
public static <T> java.util.stream.Stream<T> recover(java.util.stream.Stream<T> stream, java.util.function.Function<java.lang.Throwable,? extends T> fn)
public static <T,EX extends java.lang.Throwable> java.util.stream.Stream<T> recover(java.util.stream.Stream<T> stream, java.lang.Class<EX> type, java.util.function.Function<EX,? extends T> fn)
public static <U> java.util.stream.Stream<U> skipWhile(java.util.stream.Stream<U> stream, java.util.function.Predicate<? super U> predicate)
StreamUtils.skipWhile(Stream.of(4,3,6,7).sorted(),i->i<6).collect(Collectors.toList())
// [6,7]
stream
- predicate
- public static <U> java.util.stream.Stream<U> limit(java.util.stream.Stream<U> stream, long time, java.util.concurrent.TimeUnit unit)
public static <U> java.util.stream.Stream<U> skip(java.util.stream.Stream<U> stream, long time, java.util.concurrent.TimeUnit unit)
public static <T> java.util.stream.Stream<T> combine(java.util.stream.Stream<T> stream, java.util.function.BiPredicate<? super T,? super T> predicate, java.util.function.BinaryOperator<T> op)
public static <U> java.util.stream.Stream<U> limitWhile(java.util.stream.Stream<U> stream, java.util.function.Predicate<? super U> predicate)
StreamUtils.limitWhile(Stream.of(4,3,6,7).sorted(),i->i<6).collect(Collectors.toList());
//[4,3]
stream
- predicate
- public static <U> java.util.stream.Stream<U> limitUntil(java.util.stream.Stream<U> stream, java.util.function.Predicate<? super U> predicate)
StreamUtils.limitUntil(Stream.of(4,3,6,7),i->i==6).collect(Collectors.toList());
//[4,3]
stream
- predicate
- public static <U> java.util.stream.Stream<U> reverse(java.util.stream.Stream<U> stream)
assertThat(StreamUtils.reverse(Stream.of(1,2,3)).collect(Collectors.toList())
,equalTo(Arrays.asList(3,2,1)));
stream
- Stream to reversepublic static <U> java.util.stream.Stream<U> reversedStream(java.util.List<U> list)
StreamUtils.reversedStream(asList(1,2,3))
.map(i->i*100)
.forEach(System.out::println);
assertThat(StreamUtils.reversedStream(Arrays.asList(1,2,3)).collect(Collectors.toList())
,equalTo(Arrays.asList(3,2,1)));
list
- List to create a reversed Stream frompublic static <U> java.util.stream.Stream<U> cycle(java.util.stream.Stream<U> s)
assertThat(StreamUtils.cycle(Stream.of(1,2,3))
.limit(6)
.collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,3,1,2,3)));
s
- Stream to cyclepublic static <U> java.util.stream.Stream<U> cycle(Streamable<U> s)
s
- Streamable to cyclepublic static <U> java.util.stream.Stream<U> cycle(int times, Streamable<U> s)
assertThat(StreamUtils.cycle(3,Streamable.of(1,2,2))
.collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,2,1,2,2,1,2,2)));
s
- Streamable to cyclepublic static <U> java.util.stream.Stream<U> stream(java.lang.Iterable<U> it)
assertThat(StreamUtils.stream(Arrays.asList(1,2,3))
.collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,3)));
it
- Iterable to convert to a Streampublic static <U> java.util.stream.Stream<U> stream(java.util.Spliterator<U> it)
public static <U> java.util.stream.Stream<U> stream(java.util.Iterator<U> it)
assertThat(StreamUtils.stream(Arrays.asList(1,2,3).iterator())
.collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,3)));
it
- Iterator to convert to a Streampublic static <U> java.util.stream.Stream<U> concat(java.lang.Object o, java.util.stream.Stream<U> stream)
o
- Object to concatstream
- Stream to concatpublic static final <K,V> java.util.stream.Stream<java.util.Map.Entry<K,V>> stream(java.util.Map<K,V> it)
Map<String,String> map = new HashMap<>();
map.put("hello","world");
assertThat(StreamUtils.stream(map).collect(Collectors.toList()),equalTo(Arrays.asList(new AbstractMap.SimpleEntry("hello","world"))));
it
- Iterator to convert to a Streampublic static final <T> FutureOperations<T> futureOperations(java.util.stream.Stream<T> stream, java.util.concurrent.Executor exec)
public static final <T> T firstValue(java.util.stream.Stream<T> stream)
public static <R> ListX<R> reduce(java.util.stream.Stream<R> stream, java.lang.Iterable<? extends Monoid<R>> reducers)
Monoid<Integer> sum = Monoid.of(0,(a,b)->a+b);
Monoid<Integer> mult = Monoid.of(1,(a,b)->a*b);
val result = StreamUtils.reduce(Stream.of(1,2,3,4),Arrays.asList(sum,mult));
assertThat(result,equalTo(Arrays.asList(10,24)));
stream
- Stream to reducereducers
- Reducers to reduce Streampublic static <R> ListX<R> reduce(java.util.stream.Stream<R> stream, java.util.stream.Stream<? extends Monoid<R>> reducers)
Monoid<String> concat = Monoid.of("",(a,b)->a+b);
Monoid<String> join = Monoid.of("",(a,b)->a+","+b);
assertThat(StreamUtils.reduce(Stream.of("hello", "world", "woo!"),Stream.of(concat,join))
,equalTo(Arrays.asList("helloworldwoo!",",hello,world,woo!")));
stream
- Stream to reducereducers
- Reducers to reduce Streampublic static final <T> java.util.stream.Stream<T> cycleWhile(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
int count =0;
assertThat(StreamUtils.cycleWhile(Stream.of(1,2,2)
,next -> count++<6 )
.collect(Collectors.toList()),equalTo(Arrays.asList(1,2,2,1,2,2)));
predicate
- repeat while truepublic static final <T> java.util.stream.Stream<T> cycleUntil(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
count =0;
assertThat(StreamUtils.cycleUntil(Stream.of(1,2,2,3)
,next -> count++>10 )
.collect(Collectors.toList()),equalTo(Arrays.asList(1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2)));
predicate
- repeat while truepublic static final <T,S,R> java.util.stream.Stream<R> zipSequence(java.util.stream.Stream<T> stream, java.util.stream.Stream<? extends S> second, java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Stream<List<Integer>> zipped = StreamUtils.zip(Stream.of(1,2,3)
,ReactiveSeq.of(2,3,4),
(a,b) -> Arrays.asList(a,b));
List<Integer> zip = zipped.collect(Collectors.toList()).get(1);
assertThat(zip.get(0),equalTo(2));
assertThat(zip.get(1),equalTo(3));
second
- Monad to zip withzipper
- Zipping functionpublic static final <T,S,R> java.util.stream.Stream<R> zipAnyM(java.util.stream.Stream<T> stream, AnyM<? extends S> second, java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Stream<List<Integer>> zipped = StreamUtils.zip(Stream.of(1,2,3)
,anyM(Optional.of(2)),
(a,b) -> Arrays.asList(a,b));
List<Integer> zip = zipped.collect(Collectors.toList()).get(0);
assertThat(zip.get(0),equalTo(1));
assertThat(zip.get(1),equalTo(2));
public static final <T,S,R> java.util.stream.Stream<R> zipStream(java.util.stream.Stream<T> stream, 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)
Stream<List<Integer>> zipped = StreamUtils.zipStream(Stream.of(1,2,3)
,Stream.of(2,3,4),
(a,b) -> Arrays.asList(a,b));
List<Integer> zip = zipped.collect(Collectors.toList()).get(1);
assertThat(zip.get(0),equalTo(2));
assertThat(zip.get(1),equalTo(3));
second
- Stream to zip withzipper
- Zip funcitonpublic static final <T> java.util.stream.Stream<ListX<T>> sliding(java.util.stream.Stream<T> stream, int windowSize, int increment)
List<List<Integer>> list = StreamUtils.sliding(Stream.of(1,2,3,4,5,6)
,2,1)
.collect(Collectors.toList());
assertThat(list.get(0),hasItems(1,2));
assertThat(list.get(1),hasItems(2,3));
windowSize
- Size of sliding windowpublic static final <T> java.util.stream.Stream<Streamable<T>> window(java.util.stream.Stream<T> stream, int windowSize, int increment)
List<List<Integer>> list = StreamUtils.sliding(Stream.of(1,2,3,4,5,6)
,2,1)
.collect(Collectors.toList());
assertThat(list.get(0),hasItems(1,2));
assertThat(list.get(1),hasItems(2,3));
windowSize
- Size of sliding windowpublic static final <T> java.util.stream.Stream<ListX<T>> sliding(java.util.stream.Stream<T> stream, int windowSize)
List<List<Integer>> list = StreamUtils.sliding(Stream.of(1,2,3,4,5,6)
,2)
.collect(Collectors.toList());
assertThat(list.get(0),hasItems(1,2));
assertThat(list.get(1),hasItems(2,3));
stream
- Stream to create sliding view onwindowSize
- size of windowpublic static final <T> java.util.stream.Stream<ListX<T>> batchBySize(java.util.stream.Stream<T> stream, int groupSize)
List<List<Integer>> list = StreamUtils.grouped(Stream.of(1,2,3,4,5,6)
,3)
.collect(Collectors.toList());
assertThat(list.get(0),hasItems(1,2,3));
assertThat(list.get(1),hasItems(4,5,6));
groupSize
- Size of each Grouppublic static final <T,C extends java.util.Collection<? super T>> java.util.stream.Stream<C> batchBySize(java.util.stream.Stream<T> stream, int groupSize, java.util.function.Supplier<C> factory)
public static final <T> Streamable<T> shuffle(java.util.stream.Stream<T> stream)
public static final <T> Streamable<T> toLazyStreamable(java.util.stream.Stream<T> stream)
public static final <T> Streamable<T> toConcurrentLazyStreamable(java.util.stream.Stream<T> stream)
public static final <U,T> java.util.stream.Stream<U> scanRight(java.util.stream.Stream<T> stream, U identity, java.util.function.BiFunction<? super T,? super U,? extends U> combiner)
public static final <T> java.util.stream.Stream<T> scanLeft(java.util.stream.Stream<T> stream, Monoid<T> monoid)
assertEquals(asList("", "a", "ab", "abc"),
StreamUtils.scanLeft(Stream.of("a", "b", "c"),Reducers.toString(""))
.collect(Collectors.toList());
monoid
- public static <T> boolean xMatch(java.util.stream.Stream<T> stream, int num, java.util.function.Predicate<? super T> c)
assertTrue(StreamUtils.xMatch(Stream.of(1,2,3,5,6,7),3, i->i>4));
public static final <T> boolean noneMatch(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> c)
assertThat(StreamUtils.noneMatch(of(1,2,3,4,5),it-> it==5000),equalTo(true));
public static final <T> java.lang.String join(java.util.stream.Stream<T> stream)
public static final <T> java.lang.String join(java.util.stream.Stream<T> stream, java.lang.String sep)
public static final <T> java.lang.String join(java.util.stream.Stream<T> stream, java.lang.String sep, java.lang.String start, java.lang.String end)
public static final <T,C extends java.lang.Comparable<? super C>> java.util.Optional<T> minBy(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,? extends C> f)
public static final <T> java.util.Optional<T> min(java.util.stream.Stream<T> stream, java.util.Comparator<? super T> comparator)
public static final <T,C extends java.lang.Comparable<? super C>> java.util.Optional<T> maxBy(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,? extends C> f)
public static final <T> java.util.Optional<T> max(java.util.stream.Stream<T> stream, java.util.Comparator<? super T> comparator)
public static final <T,R> R mapReduce(java.util.stream.Stream<T> stream, Reducer<R> reducer)
reducer
- Monoid to reduce valuespublic static final <T,R> R mapReduce(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,? extends R> mapper, Monoid<R> reducer)
mapper
- Function to map Monad typereducer
- Monoid to reduce valuespublic static final <T> T foldLeft(java.util.stream.Stream<T> stream, Monoid<T> reducer)
reducer
- Use supplied Monoid to reduce values starting via foldLeftpublic static final <T> T foldLeftMapToType(java.util.stream.Stream<T> stream, Reducer<T> reducer)
reducer
- Monoid to reduce valuespublic static final <T> T foldRight(java.util.stream.Stream<T> stream, Monoid<T> reducer)
reducer
- Use supplied Monoid to reduce values starting via foldRightpublic static final <T> T foldRightMapToType(java.util.stream.Stream<T> stream, Reducer<T> reducer)
reducer
- Monoid to reduce valuespublic static final <T> Streamable<T> toStreamable(java.util.stream.Stream<T> stream)
public static final <T> java.util.Set<T> toSet(java.util.stream.Stream<T> stream)
public static final <T> java.util.List<T> toList(java.util.stream.Stream<T> stream)
public static final <T> boolean startsWith(java.util.stream.Stream<T> stream, java.lang.Iterable<T> iterable)
assertTrue(StreamUtils.startsWith(Stream.of(1,2,3,4),Arrays.asList(1,2,3)));
iterable
- public static final <T> boolean endsWith(java.util.stream.Stream<T> stream, java.lang.Iterable<T> iterable)
public static final <T> boolean startsWith(java.util.stream.Stream<T> stream, java.util.stream.Stream<T> stream2)
public static final <T> boolean startsWith(java.util.stream.Stream<T> stream, java.util.Iterator<T> iterator)
assertTrue(StreamUtils.startsWith(Stream.of(1,2,3,4),Arrays.asList(1,2,3).iterator()))
iterator
- public static final <T> ReactiveSeq<T> reactiveSeq(java.util.stream.Stream<T> stream, java.util.Optional<ReversableSpliterator> rev)
public static <T> java.util.stream.Stream<T> intersperse(java.util.stream.Stream<T> stream, T value)
assertThat(Arrays.asList(1, 0, 2, 0, 3, 0, 4),
equalTo( StreamUtils.intersperse(Stream.of(1, 2, 3, 4),0));
public static <T,U> java.util.stream.Stream<U> ofType(java.util.stream.Stream<T> stream, java.lang.Class<? extends U> type)
public static <T,U> java.util.stream.Stream<U> cast(java.util.stream.Stream<T> stream, java.lang.Class<? extends U> type)
ClassCastException
.
StreamUtils.cast(Stream.of(1, "a", 2, "b", 3),Integer.class)
// throws ClassCastException
public static final <T,R> java.util.stream.Stream<R> flatMapSequenceM(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,ReactiveSeq<? extends R>> fn)
assertThat(StreamUtils.flatMapSequenceM(Stream.of(1,2,3),
i->ReactiveSeq.of(i+2)).collect(Collectors.toList()),
equalTo(Arrays.asList(3,4,5)));
fn
- public static final <T,R> java.util.stream.Stream<R> flatMapAnyM(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,AnyM<? extends R>> fn)
public static final <T,R> java.util.stream.Stream<R> flatMapIterable(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> fn)
assertThat(StreamUtils.flatMapCollection(Stream.of(20),i->Arrays.asList(1,2,i))
.collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,20)));
public static final <T,R> java.util.stream.Stream<R> flatMapStream(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,? extends java.util.stream.BaseStream<? extends R,?>> fn)
assertThat(StreamUtils.flatMapStream(Stream.of(1,2,3),
i->Stream.of(i)).collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,3)));
public static final <T,R> java.util.stream.Stream<R> flatMapOptional(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,java.util.Optional<? extends R>> fn)
assertThat(StreamUtils.flatMapOptional(Stream.of(1,2,3,null),
Optional::ofNullable)
.collect(Collectors.toList()),
equalTo(Arrays.asList(1,2,3)));
public static final <T,R> ReactiveSeq<R> flatten(java.util.stream.Stream<T> stream)
public static final <T,R> java.util.stream.Stream<R> flatMapCompletableFuture(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,java.util.concurrent.CompletableFuture<? extends R>> fn)
assertThat(StreamUtils.flatMapCompletableFuture(Stream.of(1,2,3),
i->CompletableFuture.completedFuture(i+2))
.collect(Collectors.toList()),
equalTo(Arrays.asList(3,4,5)));
public static final <T> java.util.stream.Stream<java.lang.Character> flatMapCharSequence(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,java.lang.CharSequence> fn)
List<Character> result = StreamUtils.liftAndBindCharSequence(Stream.of("input.file"),
.i->"hello world")
.toList();
assertThat(result,equalTo(Arrays.asList('h','e','l','l','o',' ','w','o','r','l','d')));
fn
- public static final <T> java.util.stream.Stream<java.lang.String> flatMapFile(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,java.io.File> fn)
List<String> result = StreamUtils.liftAndBindFile(Stream.of("input.file")
.map(getClass().getClassLoader()::getResource)
.peek(System.out::println)
.map(URL::getFile)
,File::new)
.toList();
assertThat(result,equalTo(Arrays.asList("hello","world")));
fn
- public static final <T> java.util.stream.Stream<java.lang.String> flatMapURL(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,java.net.URL> fn)
List<String> result = StreamUtils.liftAndBindURL(Stream.of("input.file")
,getClass().getClassLoader()::getResource)
.collect(Collectors.toList();
assertThat(result,equalTo(Arrays.asList("hello","world")));
fn
- public static final <T> java.util.stream.Stream<java.lang.String> flatMapBufferedReader(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,java.io.BufferedReader> fn)
Listresult = StreamUtils.liftAndBindBufferedReader(Stream.of("input.file") .map(getClass().getClassLoader()::getResourceAsStream) .map(InputStreamReader::new) ,BufferedReader::new) .collect(Collectors.toList(); assertThat(result,equalTo(Arrays.asList("hello","world")));
fn
- public static final <A> org.jooq.lambda.tuple.Tuple2<java.util.Iterator<A>,java.util.Iterator<A>> toBufferingDuplicator(java.util.Iterator<A> iterator)
public static final <A> org.jooq.lambda.tuple.Tuple2<java.util.Iterator<A>,java.util.Iterator<A>> toBufferingDuplicator(java.util.Iterator<A> iterator, long pos)
public static final <A> ListX<java.util.Iterator<A>> toBufferingCopier(java.util.Iterator<A> iterator, int copies)
public static final <A> CollectionX<A> toLazyCollection(java.util.stream.Stream<A> stream)
public static final <A> CollectionX<A> toLazyCollection(java.util.Iterator<A> iterator)
public static final <A> CollectionX<A> toConcurrentLazyCollection(java.util.stream.Stream<A> stream)
stream
- public static final <A> CollectionX<A> toConcurrentLazyCollection(java.util.Iterator<A> iterator)
public static final <T> java.util.stream.Stream<Streamable<T>> windowByTime(java.util.stream.Stream<T> stream, long time, java.util.concurrent.TimeUnit t)
public static final <T> java.util.stream.Stream<ListX<T>> batchByTime(java.util.stream.Stream<T> stream, long time, java.util.concurrent.TimeUnit t)
public static final <T,C extends java.util.Collection<? super T>> java.util.stream.Stream<C> batchByTime(java.util.stream.Stream<T> stream, long time, java.util.concurrent.TimeUnit t, java.util.function.Supplier<C> factory)
public static final <T> java.util.stream.Stream<ListX<T>> groupedStatefullyUntil(java.util.stream.Stream<T> stream, java.util.function.BiPredicate<ListX<? super T>,? super T> predicate)
public static final <T> java.util.stream.Stream<ListX<T>> batchWhile(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
public static final <T,C extends java.util.Collection<? super T>> java.util.stream.Stream<C> batchWhile(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate, java.util.function.Supplier<C> factory)
public static final <T> java.util.stream.Stream<ListX<T>> batchUntil(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
public static final <T> java.util.stream.Stream<ListX<T>> batchBySizeAndTime(java.util.stream.Stream<T> stream, int size, long time, java.util.concurrent.TimeUnit t)
public static final <T,C extends java.util.Collection<? super T>> java.util.stream.Stream<C> batchBySizeAndTime(java.util.stream.Stream<T> stream, int size, long time, java.util.concurrent.TimeUnit t, java.util.function.Supplier<C> factory)
public static final <T> java.util.stream.Stream<T> debounce(java.util.stream.Stream<T> stream, long time, java.util.concurrent.TimeUnit t)
public static final <T> java.util.stream.Stream<T> onePer(java.util.stream.Stream<T> stream, long time, java.util.concurrent.TimeUnit t)
public static final <T> java.util.stream.Stream<T> jitter(java.util.stream.Stream<T> stream, long jitterInNanos)
public static final <T> java.util.stream.Stream<T> fixedDelay(java.util.stream.Stream<T> stream, long time, java.util.concurrent.TimeUnit unit)
public static final <T> java.util.stream.Stream<T> xPer(java.util.stream.Stream<T> stream, int x, long time, java.util.concurrent.TimeUnit t)
public static final <T> HotStream<T> hotStream(java.util.stream.Stream<T> stream, java.util.concurrent.Executor exec)
public static final <T> HotStream<T> primedHotStream(java.util.stream.Stream<T> stream, java.util.concurrent.Executor exec)
public static final <T> PausableHotStream<T> pausableHotStream(java.util.stream.Stream<T> stream, java.util.concurrent.Executor exec)
public static final <T> PausableHotStream<T> primedPausableHotStream(java.util.stream.Stream<T> stream, java.util.concurrent.Executor exec)