public interface Seq<T> extends java.util.stream.Stream<T>, Iterable<T>
Stream
that adds all sorts of useful methods that work only because
it is sequential and ordered.java.util.stream.Stream.Builder<T>
Modifier and Type | Method and Description |
---|---|
default <U> Seq<U> |
cast(Class<U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
static <T,U> Seq<U> |
cast(java.util.stream.Stream<T> stream,
Class<U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
void |
close() |
static <T> Seq<T> |
concat(java.util.stream.Stream<T>... streams)
Concatenate a number of streams.
|
default Seq<T> |
concat(java.util.stream.Stream<T> other)
Concatenate two streams.
|
default Seq<T> |
concat(T... other)
Concatenate two streams.
|
default Seq<T> |
concat(T other)
Concatenate two streams.
|
default Seq<T> |
cycle()
Repeat a stream infinitely.
|
static <T> Seq<T> |
cycle(java.util.stream.Stream<T> stream)
Repeat a stream infinitely.
|
Seq<T> |
distinct() |
default Tuple2<Seq<T>,Seq<T>> |
duplicate()
Duplicate a Streams into two equivalent Streams.
|
static <T> Tuple2<Seq<T>,Seq<T>> |
duplicate(java.util.stream.Stream<T> stream)
Duplicate a Streams into two equivalent Streams.
|
static <T> Seq<T> |
empty() |
Seq<T> |
filter(java.util.function.Predicate<? super T> predicate) |
<R> Seq<R> |
flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper) |
java.util.stream.DoubleStream |
flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper) |
java.util.stream.IntStream |
flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper) |
java.util.stream.LongStream |
flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper) |
static <T,U> U |
foldLeft(java.util.stream.Stream<T> stream,
U seed,
java.util.function.BiFunction<U,? super T,U> function)
Fold a stream to the left.
|
default <U> U |
foldLeft(U seed,
java.util.function.BiFunction<U,? super T,U> function)
Fold a Stream to the left.
|
static <T,U> U |
foldRight(java.util.stream.Stream<T> stream,
U seed,
java.util.function.BiFunction<? super T,U,U> function)
Fold a stream to the right.
|
default <U> U |
foldRight(U seed,
java.util.function.BiFunction<? super T,U,U> function)
Fold a Stream to the right.
|
default void |
forEach(java.util.function.Consumer<? super T> action) |
static Seq<Void> |
generate() |
static <T> Seq<T> |
generate(java.util.function.Supplier<T> s) |
static <T> Seq<T> |
generate(T value) |
default <K> Map<K,List<T>> |
groupBy(java.util.function.Function<? super T,? extends K> classifier)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.groupingBy(Function) collector. |
default <K,A,D> Map<K,D> |
groupBy(java.util.function.Function<? super T,? extends K> classifier,
java.util.stream.Collector<? super T,A,D> downstream)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.groupingBy(Function, Collector) collector. |
default <K,D,A,M extends Map<K,D>> |
groupBy(java.util.function.Function<? super T,? extends K> classifier,
java.util.function.Supplier<M> mapFactory,
java.util.stream.Collector<? super T,A,D> downstream)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.groupingBy(Function, Supplier, Collector) collector. |
static <T,K> Map<K,List<T>> |
groupBy(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,? extends K> classifier)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.groupingBy(Function) collector. |
static <T,K,A,D> Map<K,D> |
groupBy(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,? extends K> classifier,
java.util.stream.Collector<? super T,A,D> downstream)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.groupingBy(Function, Collector) collector. |
static <T,K,D,A,M extends Map<K,D>> |
groupBy(java.util.stream.Stream<T> stream,
java.util.function.Function<? super T,? extends K> classifier,
java.util.function.Supplier<M> mapFactory,
java.util.stream.Collector<? super T,A,D> downstream)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.groupingBy(Function, Supplier, Collector) collector. |
static <T> Seq<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.
|
default Seq<T> |
intersperse(T value)
Returns a stream with a given value interspersed between any two values of this stream.
|
static <T> Seq<T> |
iterate(T seed,
java.util.function.UnaryOperator<T> f) |
default String |
join()
Shortcut for calling
Stream.collect(Collector) with a
Collectors.joining()
collector. |
default String |
join(CharSequence delimiter)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.joining(CharSequence)
collector. |
default String |
join(CharSequence delimiter,
CharSequence prefix,
CharSequence suffix)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.joining(CharSequence, CharSequence, CharSequence)
collector. |
static String |
join(java.util.stream.Stream<?> stream)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.joining()
collector. |
static String |
join(java.util.stream.Stream<?> stream,
CharSequence delimiter)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.joining(CharSequence)
collector. |
static String |
join(java.util.stream.Stream<?> stream,
CharSequence delimiter,
CharSequence prefix,
CharSequence suffix)
Shortcut for calling
Stream.collect(Collector) with a
Collectors.joining(CharSequence, CharSequence, CharSequence)
collector. |
Seq<T> |
limit(long maxSize) |
static <T> Seq<T> |
limit(java.util.stream.Stream<T> stream,
long elements)
Returns a stream limited to n elements.
|
default Seq<T> |
limitUntil(java.util.function.Predicate<? super T> predicate)
Returns a stream limited to all elements for which a predicate evaluates to
false . |
static <T> Seq<T> |
limitUntil(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate)
Returns a stream limited to all elements for which a predicate evaluates to
true . |
default Seq<T> |
limitWhile(java.util.function.Predicate<? super T> predicate)
Returns a stream limited to all elements for which a predicate evaluates to
true . |
static <T> Seq<T> |
limitWhile(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate)
Returns a stream limited to all elements for which a predicate evaluates to
true . |
<R> Seq<R> |
map(java.util.function.Function<? super T,? extends R> mapper) |
java.util.stream.DoubleStream |
mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper) |
java.util.stream.IntStream |
mapToInt(java.util.function.ToIntFunction<? super T> mapper) |
java.util.stream.LongStream |
mapToLong(java.util.function.ToLongFunction<? super T> mapper) |
default <U extends Comparable<U>> |
maxBy(java.util.function.Function<T,U> function)
Get the maximum value by a function.
|
default <U> Optional<T> |
maxBy(java.util.function.Function<T,U> function,
Comparator<? super U> comparator)
Get the maximum value by a function.
|
default <U extends Comparable<U>> |
minBy(java.util.function.Function<T,U> function)
Get the maximum value by a function.
|
default <U> Optional<T> |
minBy(java.util.function.Function<T,U> function,
Comparator<? super U> comparator)
Get the maximum value by a function.
|
static <T> Seq<T> |
of(T... values) |
static <T> Seq<T> |
of(T value) |
default <U> Seq<U> |
ofType(Class<U> type)
Keep only those elements in a stream that are of a given type.
|
static <T,U> Seq<U> |
ofType(java.util.stream.Stream<T> stream,
Class<U> type)
Keep only those elements in a stream that are of a given type.
|
Seq<T> |
onClose(Runnable closeHandler) |
default Seq<T> |
parallel() |
default Tuple2<Seq<T>,Seq<T>> |
partition(java.util.function.Predicate<? super T> predicate)
Partition a stream into two given a predicate.
|
static <T> Tuple2<Seq<T>,Seq<T>> |
partition(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate)
Partition a stream into two given a predicate.
|
Seq<T> |
peek(java.util.function.Consumer<? super T> action) |
default Seq<T> |
reverse()
Reverse a stream.
|
static <T> Seq<T> |
reverse(java.util.stream.Stream<T> stream)
Reverse a stream.
|
static <T,U> Seq<U> |
scanLeft(java.util.stream.Stream<T> stream,
U seed,
java.util.function.BiFunction<U,? super T,U> function)
Scan a stream to the left.
|
default <U> Seq<U> |
scanLeft(U seed,
java.util.function.BiFunction<U,? super T,U> function)
Scan a stream to the left.
|
static <T,U> Seq<U> |
scanRight(java.util.stream.Stream<T> stream,
U seed,
java.util.function.BiFunction<? super T,U,U> function)
Scan a stream to the right.
|
default <U> Seq<U> |
scanRight(U seed,
java.util.function.BiFunction<? super T,U,U> function)
Scan a stream to the right.
|
static <T> Seq<T> |
seq(Iterable<T> iterable)
Wrap an Iterable into a Seq.
|
static <T> Seq<T> |
seq(Iterator<T> iterator)
Wrap an Iterator into a Seq.
|
static <K,V> Seq<Tuple2<K,V>> |
seq(Map<K,V> map)
Wrap a Map into a Seq.
|
static <T> Seq<T> |
seq(Optional<T> optional)
Wrap an Optional into a Seq.
|
static <T> Seq<T> |
seq(java.util.stream.Stream<T> stream)
Wrap a Stream into a Seq.
|
default Seq<T> |
sequential() |
default Seq<T> |
shuffle()
Shuffle a stream
// e.g. (2, 3, 1)
Seq.of(1, 2, 3).shuffle()
|
default Seq<T> |
shuffle(Random random)
Shuffle a stream using specified source of randomness
// e.g. (2, 3, 1)
Seq.of(1, 2, 3).shuffle(new Random())
|
static <T> Seq<T> |
shuffle(java.util.stream.Stream<T> stream)
Shuffle a stream
// e.g. (2, 3, 1)
Seq.of(1, 2, 3).shuffle()
|
static <T> Seq<T> |
shuffle(java.util.stream.Stream<T> stream,
Random random)
Shuffle a stream using specified source of randomness
// e.g. (2, 3, 1)
Seq.of(1, 2, 3).shuffle(new Random())
|
Seq<T> |
skip(long n) |
static <T> Seq<T> |
skip(java.util.stream.Stream<T> stream,
long elements)
Returns a stream with n elements skipped.
|
default Seq<T> |
skipUntil(java.util.function.Predicate<? super T> predicate)
Returns a stream with all elements skipped for which a predicate evaluates to
false . |
static <T> Seq<T> |
skipUntil(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate)
Returns a stream with all elements skipped for which a predicate evaluates to
false . |
default Seq<T> |
skipWhile(java.util.function.Predicate<? super T> predicate)
Returns a stream with all elements skipped for which a predicate evaluates to
true . |
static <T> Seq<T> |
skipWhile(java.util.stream.Stream<T> stream,
java.util.function.Predicate<? super T> predicate)
Returns a stream with all elements skipped for which a predicate evaluates to
true . |
default Seq<T> |
slice(long from,
long to)
Returns a limited interval from a given Stream.
|
static <T> Seq<T> |
slice(java.util.stream.Stream<T> stream,
long from,
long to)
Returns a limited interval from a given Stream.
|
Seq<T> |
sorted() |
Seq<T> |
sorted(Comparator<? super T> comparator) |
default Tuple2<Seq<T>,Seq<T>> |
splitAt(long position)
Split a stream at a given position.
|
static <T> Tuple2<Seq<T>,Seq<T>> |
splitAt(java.util.stream.Stream<T> stream,
long position)
Split a stream at a given position.
|
default Tuple2<Optional<T>,Seq<T>> |
splitAtHead()
Split a stream at the head.
|
static <T> Tuple2<Optional<T>,Seq<T>> |
splitAtHead(java.util.stream.Stream<T> stream)
Split a stream at the head.
|
default Spliterator<T> |
spliterator() |
java.util.stream.Stream<T> |
stream()
The underlying
Stream implementation. |
static <T,C extends Collection<T>> |
toCollection(java.util.stream.Stream<T> stream,
java.util.function.Supplier<C> collectionFactory)
Collect a Stream into a List.
|
default <C extends Collection<T>> |
toCollection(java.util.function.Supplier<C> collectionFactory)
Collect a Stream into a Collection.
|
default List<T> |
toList()
Collect a Stream into a List.
|
static <T> List<T> |
toList(java.util.stream.Stream<T> stream)
Collect a Stream into a List.
|
default <K,V> Map<K,V> |
toMap(java.util.function.Function<T,K> keyMapper,
java.util.function.Function<T,V> valueMapper)
Collect a Stream into a Map.
|
static <T,K,V> Map<K,V> |
toMap(java.util.stream.Stream<T> stream,
java.util.function.Function<T,K> keyMapper,
java.util.function.Function<T,V> valueMapper)
Collect a Stream into a Map.
|
static <T,K,V> Map<K,V> |
toMap(java.util.stream.Stream<Tuple2<K,V>> stream)
Collect a Stream of
Tuple2 into a Map. |
default Set<T> |
toSet()
Collect a Stream into a Set.
|
static <T> Set<T> |
toSet(java.util.stream.Stream<T> stream)
Collect a Stream into a Set.
|
static String |
toString(java.util.stream.Stream<?> stream)
Consume a stream and concatenate all elements.
|
static String |
toString(java.util.stream.Stream<?> stream,
String separator)
Consume a stream and concatenate all elements using a separator.
|
default String |
toString(String separator)
Consume a stream and concatenate all elements using a separator.
|
static <T,U> Seq<T> |
unfold(U seed,
java.util.function.Function<U,Optional<Tuple2<T,U>>> unfolder)
Unfold a function into a stream.
|
default Seq<T> |
unordered() |
static <T1,T2> Tuple2<Seq<T1>,Seq<T2>> |
unzip(java.util.stream.Stream<Tuple2<T1,T2>> stream)
Unzip one Stream into two.
|
static <T1,T2,U1,U2> |
unzip(java.util.stream.Stream<Tuple2<T1,T2>> stream,
java.util.function.BiFunction<T1,T2,Tuple2<U1,U2>> unzipper)
Unzip one Stream into two.
|
static <T1,T2,U1,U2> |
unzip(java.util.stream.Stream<Tuple2<T1,T2>> stream,
java.util.function.Function<T1,U1> leftUnzipper,
java.util.function.Function<T2,U2> rightUnzipper)
Unzip one Stream into two.
|
static <T1,T2,U1,U2> |
unzip(java.util.stream.Stream<Tuple2<T1,T2>> stream,
java.util.function.Function<Tuple2<T1,T2>,Tuple2<U1,U2>> unzipper)
Unzip one Stream into two.
|
default <U> Seq<Tuple2<T,U>> |
zip(Seq<U> other)
Zip two streams into one.
|
default <U,R> Seq<R> |
zip(Seq<U> other,
java.util.function.BiFunction<T,U,R> zipper)
Zip two streams into one using a
BiFunction to produce resulting values. |
static <T1,T2> Seq<Tuple2<T1,T2>> |
zip(java.util.stream.Stream<T1> left,
java.util.stream.Stream<T2> right)
Zip two streams into one.
|
static <T1,T2,R> Seq<R> |
zip(java.util.stream.Stream<T1> left,
java.util.stream.Stream<T2> right,
java.util.function.BiFunction<T1,T2,R> zipper)
Zip two streams into one using a
BiFunction to produce resulting values. |
default Seq<Tuple2<T,Long>> |
zipWithIndex()
Zip a Stream with a corresponding Stream of indexes.
|
static <T> Seq<Tuple2<T,Long>> |
zipWithIndex(java.util.stream.Stream<T> stream)
Zip a Stream with a corresponding Stream of indexes.
|
allMatch, anyMatch, builder, collect, collect, concat, count, findAny, findFirst, forEachOrdered, max, min, noneMatch, reduce, reduce, reduce, toArray, toArray
isParallel, iterator
java.util.stream.Stream<T> stream()
Stream
implementation.default Seq<T> concat(java.util.stream.Stream<T> other)
// (1, 2, 3, 4, 5, 6)
Seq.of(1, 2, 3).concat(Seq.of(4, 5, 6))
concat(Stream[])
default Seq<T> concat(T other)
// (1, 2, 3, 4)
Seq.of(1, 2, 3).concat(4)
concat(Stream[])
default Seq<T> concat(T... other)
// (1, 2, 3, 4, 5, 6)
Seq.of(1, 2, 3).concat(4, 5, 6)
concat(Stream[])
default Seq<T> cycle()
// (1, 2, 3, 1, 2, 3, ...)
Seq.of(1, 2, 3).cycle();
cycle(Stream)
default <U> Seq<Tuple2<T,U>> zip(Seq<U> other)
// (tuple(1, "a"), tuple(2, "b"), tuple(3, "c"))
Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c"))
zip(Stream, Stream)
default <U,R> Seq<R> zip(Seq<U> other, java.util.function.BiFunction<T,U,R> zipper)
BiFunction
to produce resulting values.
// ("1:a", "2:b", "3:c")
Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c"), (i, s) -> i + ":" + s)
zip(Seq, BiFunction)
default Seq<Tuple2<T,Long>> zipWithIndex()
// (tuple("a", 0), tuple("b", 1), tuple("c", 2))
Seq.of("a", "b", "c").zipWithIndex()
zipWithIndex(Stream)
default <U> U foldLeft(U seed, java.util.function.BiFunction<U,? super T,U> function)
// "abc"
Seq.of("a", "b", "c").foldLeft("", (u, t) -> u + t)
default <U> U foldRight(U seed, java.util.function.BiFunction<? super T,U,U> function)
// "cba"
Seq.of("a", "b", "c").foldRight("", (t, u) -> u + t)
default <U> Seq<U> scanLeft(U seed, java.util.function.BiFunction<U,? super T,U> function)
// ("", "a", "ab", "abc")
Seq.of("a", "b", "c").scanLeft("", (u, t) -> u + t)
default <U> Seq<U> scanRight(U seed, java.util.function.BiFunction<? super T,U,U> function)
// ("", "c", "cb", "cba")
Seq.of("a", "b", "c").scanRight("", (t, u) -> u + t)
default Seq<T> shuffle(Random random)
// e.g. (2, 3, 1)
Seq.of(1, 2, 3).shuffle(new Random())
default Seq<T> skipWhile(java.util.function.Predicate<? super T> predicate)
true
.
// (3, 4, 5)
Seq.of(1, 2, 3, 4, 5).skipWhile(i -> i < 3)
skipWhile(Stream, Predicate)
default Seq<T> skipUntil(java.util.function.Predicate<? super T> predicate)
false
.
// (3, 4, 5)
Seq.of(1, 2, 3, 4, 5).skipUntil(i -> i == 3)
skipUntil(Stream, Predicate)
default Seq<T> limitWhile(java.util.function.Predicate<? super T> predicate)
true
.
// (1, 2)
Seq.of(1, 2, 3, 4, 5).limitWhile(i -> i < 3)
limitWhile(Stream, Predicate)
default Seq<T> limitUntil(java.util.function.Predicate<? super T> predicate)
false
.
// (1, 2)
Seq.of(1, 2, 3, 4, 5).limitUntil(i -> i == 3)
limitUntil(Stream, Predicate)
default Seq<T> intersperse(T value)
// (1, 0, 2, 0, 3, 0, 4)
Seq.of(1, 2, 3, 4).intersperse(0)
intersperse(Stream, Object)
default Tuple2<Seq<T>,Seq<T>> duplicate()
// tuple((1, 2, 3), (1, 2, 3))
Seq.of(1, 2, 3).duplicate()
duplicate(Stream)
default Tuple2<Seq<T>,Seq<T>> partition(java.util.function.Predicate<? super T> predicate)
// tuple((1, 3, 5), (2, 4, 6))
Seq.of(1, 2, 3, 4, 5, 6).partition(i -> i % 2 != 0)
partition(Stream, Predicate)
default Tuple2<Seq<T>,Seq<T>> splitAt(long position)
// tuple((1, 2, 3), (4, 5, 6))
Seq.of(1, 2, 3, 4, 5, 6).splitAt(3)
splitAt(Stream, long)
default Tuple2<Optional<T>,Seq<T>> splitAtHead()
// tuple(1, (2, 3, 4, 5, 6))
Seq.of(1, 2, 3, 4, 5, 6).splitHead(3)
splitAt(Stream, long)
default Seq<T> slice(long from, long to)
// (4, 5)
Seq.of(1, 2, 3, 4, 5, 6).slice(3, 5)
slice(Stream, long, long)
default <C extends Collection<T>> C toCollection(java.util.function.Supplier<C> collectionFactory)
toCollection(Stream, Supplier)
default List<T> toList()
toList(Stream)
default Set<T> toSet()
toSet(Stream)
default <K,V> Map<K,V> toMap(java.util.function.Function<T,K> keyMapper, java.util.function.Function<T,V> valueMapper)
toMap(Stream, Function, Function)
default String toString(String separator)
default <U extends Comparable<U>> Optional<T> minBy(java.util.function.Function<T,U> function)
default <U> Optional<T> minBy(java.util.function.Function<T,U> function, Comparator<? super U> comparator)
default <U extends Comparable<U>> Optional<T> maxBy(java.util.function.Function<T,U> function)
default <U> Optional<T> maxBy(java.util.function.Function<T,U> function, Comparator<? super U> comparator)
default <U> Seq<U> ofType(Class<U> type)
// (1, 2, 3)
Seq.of(1, "a", 2, "b", 3).ofType(Integer.class)
ofType(Stream, Class)
default <U> Seq<U> cast(Class<U> type)
ClassCastException
.
// ClassCastException
Seq.of(1, "a", 2, "b", 3).cast(Integer.class)
cast(Stream, Class)
default <K> Map<K,List<T>> groupBy(java.util.function.Function<? super T,? extends K> classifier)
Stream.collect(Collector)
with a
Collectors.groupingBy(Function)
collector.default <K,A,D> Map<K,D> groupBy(java.util.function.Function<? super T,? extends K> classifier, java.util.stream.Collector<? super T,A,D> downstream)
Stream.collect(Collector)
with a
Collectors.groupingBy(Function, Collector)
collector.default <K,D,A,M extends Map<K,D>> M groupBy(java.util.function.Function<? super T,? extends K> classifier, java.util.function.Supplier<M> mapFactory, java.util.stream.Collector<? super T,A,D> downstream)
Stream.collect(Collector)
with a
Collectors.groupingBy(Function, Supplier, Collector)
collector.default String join()
Stream.collect(Collector)
with a
Collectors.joining()
collector.default String join(CharSequence delimiter)
Stream.collect(Collector)
with a
Collectors.joining(CharSequence)
collector.default String join(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Stream.collect(Collector)
with a
Collectors.joining(CharSequence, CharSequence, CharSequence)
collector.static <T> Seq<T> of(T value)
of
in interface java.util.stream.Stream<T>
Stream.of(Object)
@SafeVarargs static <T> Seq<T> of(T... values)
of
in interface java.util.stream.Stream<T>
Stream.of(Object[])
static <T> Seq<T> empty()
empty
in interface java.util.stream.Stream<T>
Stream.empty()
static <T> Seq<T> iterate(T seed, java.util.function.UnaryOperator<T> f)
iterate
in interface java.util.stream.Stream<T>
Stream.iterate(Object, UnaryOperator)
static <T> Seq<T> generate(T value)
generate
in interface java.util.stream.Stream<T>
Stream.generate(Supplier)
static <T> Seq<T> generate(java.util.function.Supplier<T> s)
generate
in interface java.util.stream.Stream<T>
Stream.generate(Supplier)
static <T> Seq<T> seq(java.util.stream.Stream<T> stream)
static <T> Seq<T> cycle(java.util.stream.Stream<T> stream)
// (1, 2, 3, 1, 2, 3, ...)
Seq.of(1, 2, 3).cycle();
static <T1,T2> Tuple2<Seq<T1>,Seq<T2>> unzip(java.util.stream.Stream<Tuple2<T1,T2>> stream)
// tuple((1, 2, 3), (a, b, c))
Seq.unzip(Seq.of(tuple(1, "a"), tuple(2, "b"), tuple(3, "c")));
static <T1,T2,U1,U2> Tuple2<Seq<U1>,Seq<U2>> unzip(java.util.stream.Stream<Tuple2<T1,T2>> stream, java.util.function.Function<T1,U1> leftUnzipper, java.util.function.Function<T2,U2> rightUnzipper)
// tuple((1, 2, 3), (a, b, c))
Seq.unzip(Seq.of(tuple(1, "a"), tuple(2, "b"), tuple(3, "c")));
static <T1,T2,U1,U2> Tuple2<Seq<U1>,Seq<U2>> unzip(java.util.stream.Stream<Tuple2<T1,T2>> stream, java.util.function.Function<Tuple2<T1,T2>,Tuple2<U1,U2>> unzipper)
// tuple((1, 2, 3), (a, b, c))
Seq.unzip(Seq.of(tuple(1, "a"), tuple(2, "b"), tuple(3, "c")));
static <T1,T2,U1,U2> Tuple2<Seq<U1>,Seq<U2>> unzip(java.util.stream.Stream<Tuple2<T1,T2>> stream, java.util.function.BiFunction<T1,T2,Tuple2<U1,U2>> unzipper)
// tuple((1, 2, 3), (a, b, c))
Seq.unzip(Seq.of(tuple(1, "a"), tuple(2, "b"), tuple(3, "c")));
static <T1,T2> Seq<Tuple2<T1,T2>> zip(java.util.stream.Stream<T1> left, java.util.stream.Stream<T2> right)
// (tuple(1, "a"), tuple(2, "b"), tuple(3, "c"))
Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c"))
static <T1,T2,R> Seq<R> zip(java.util.stream.Stream<T1> left, java.util.stream.Stream<T2> right, java.util.function.BiFunction<T1,T2,R> zipper)
BiFunction
to produce resulting values.
// ("1:a", "2:b", "3:c")
Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c"), (i, s) -> i + ":" + s)
static <T> Seq<Tuple2<T,Long>> zipWithIndex(java.util.stream.Stream<T> stream)
// (tuple("a", 0), tuple("b", 1), tuple("c", 2))
Seq.of("a", "b", "c").zipWithIndex()
static <T,U> U foldLeft(java.util.stream.Stream<T> stream, U seed, java.util.function.BiFunction<U,? super T,U> function)
// "abc"
Seq.of("a", "b", "c").foldLeft("", (u, t) -> u + t)
static <T,U> U foldRight(java.util.stream.Stream<T> stream, U seed, java.util.function.BiFunction<? super T,U,U> function)
// "cba"
Seq.of("a", "b", "c").foldRight("", (t, u) -> u + t)
static <T,U> Seq<U> scanLeft(java.util.stream.Stream<T> stream, U seed, java.util.function.BiFunction<U,? super T,U> function)
// ("", "a", "ab", "abc")
Seq.of("a", "b", "c").scanLeft("", (u, t) -> u + t)
static <T,U> Seq<U> scanRight(java.util.stream.Stream<T> stream, U seed, java.util.function.BiFunction<? super T,U,U> function)
// ("", "c", "cb", "cba")
Seq.of("a", "b", "c").scanRight("", (t, u) -> u + t)
static <T,U> Seq<T> unfold(U seed, java.util.function.Function<U,Optional<Tuple2<T,U>>> unfolder)
// (1, 2, 3, 4, 5)
Seq.unfold(1, i -> i <= 6 ? Optional.of(tuple(i, i + 1)) : Optional.empty())
static <T> Seq<T> reverse(java.util.stream.Stream<T> stream)
// (3, 2, 1)
Seq.of(1, 2, 3).reverse()
static <T> Seq<T> shuffle(java.util.stream.Stream<T> stream)
// e.g. (2, 3, 1)
Seq.of(1, 2, 3).shuffle()
static <T> Seq<T> shuffle(java.util.stream.Stream<T> stream, Random random)
// e.g. (2, 3, 1)
Seq.of(1, 2, 3).shuffle(new Random())
@SafeVarargs static <T> Seq<T> concat(java.util.stream.Stream<T>... streams)
// (1, 2, 3, 4, 5, 6)
Seq.of(1, 2, 3).concat(Seq.of(4, 5, 6))
static <T> Tuple2<Seq<T>,Seq<T>> duplicate(java.util.stream.Stream<T> stream)
// tuple((1, 2, 3), (1, 2, 3))
Seq.of(1, 2, 3).duplicate()
static String toString(java.util.stream.Stream<?> stream)
static String toString(java.util.stream.Stream<?> stream, String separator)
static <T,C extends Collection<T>> C toCollection(java.util.stream.Stream<T> stream, java.util.function.Supplier<C> collectionFactory)
static <T> List<T> toList(java.util.stream.Stream<T> stream)
static <T> Set<T> toSet(java.util.stream.Stream<T> stream)
static <T,K,V> Map<K,V> toMap(java.util.stream.Stream<Tuple2<K,V>> stream)
Tuple2
into a Map.static <T,K,V> Map<K,V> toMap(java.util.stream.Stream<T> stream, java.util.function.Function<T,K> keyMapper, java.util.function.Function<T,V> valueMapper)
static <T> Seq<T> slice(java.util.stream.Stream<T> stream, long from, long to)
// (4, 5)
Seq.of(1, 2, 3, 4, 5, 6).slice(3, 5)
static <T> Seq<T> skip(java.util.stream.Stream<T> stream, long elements)
// (4, 5, 6)
Seq.of(1, 2, 3, 4, 5, 6).skip(3)
static <T> Seq<T> skipWhile(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
true
.
// (3, 4, 5)
Seq.of(1, 2, 3, 4, 5).skipWhile(i -> i < 3)
static <T> Seq<T> skipUntil(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
false
.
// (3, 4, 5)
Seq.of(1, 2, 3, 4, 5).skipUntil(i -> i == 3)
static <T> Seq<T> limit(java.util.stream.Stream<T> stream, long elements)
// (1, 2, 3)
Seq.of(1, 2, 3, 4, 5, 6).limit(3)
static <T> Seq<T> limitWhile(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
true
.
// (1, 2)
Seq.of(1, 2, 3, 4, 5).limitWhile(i -> i < 3)
static <T> Seq<T> limitUntil(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
true
.
// (1, 2)
Seq.of(1, 2, 3, 4, 5).limitUntil(i -> i == 3)
static <T> Seq<T> intersperse(java.util.stream.Stream<T> stream, T value)
// (1, 0, 2, 0, 3, 0, 4)
Seq.of(1, 2, 3, 4).intersperse(0)
static <T> Tuple2<Seq<T>,Seq<T>> partition(java.util.stream.Stream<T> stream, java.util.function.Predicate<? super T> predicate)
// tuple((1, 3, 5), (2, 4, 6))
Seq.of(1, 2, 3, 4, 5, 6).partition(i -> i % 2 != 0)
static <T> Tuple2<Seq<T>,Seq<T>> splitAt(java.util.stream.Stream<T> stream, long position)
// tuple((1, 2, 3), (4, 5, 6))
Seq.of(1, 2, 3, 4, 5, 6).splitAt(3)
static <T> Tuple2<Optional<T>,Seq<T>> splitAtHead(java.util.stream.Stream<T> stream)
// tuple(1, (2, 3, 4, 5, 6))
Seq.of(1, 2, 3, 4, 5, 6).splitHead(3)
static <T,U> Seq<U> ofType(java.util.stream.Stream<T> stream, Class<U> type)
// (1, 2, 3)
Seq.of(1, "a", 2, "b", 3).ofType(Integer.class)
static <T,U> Seq<U> cast(java.util.stream.Stream<T> stream, Class<U> type)
ClassCastException
.
// ClassCastException
Seq.of(1, "a", 2, "b", 3).cast(Integer.class)
static <T,K> Map<K,List<T>> groupBy(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,? extends K> classifier)
Stream.collect(Collector)
with a
Collectors.groupingBy(Function)
collector.static <T,K,A,D> Map<K,D> groupBy(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,? extends K> classifier, java.util.stream.Collector<? super T,A,D> downstream)
Stream.collect(Collector)
with a
Collectors.groupingBy(Function, Collector)
collector.static <T,K,D,A,M extends Map<K,D>> M groupBy(java.util.stream.Stream<T> stream, java.util.function.Function<? super T,? extends K> classifier, java.util.function.Supplier<M> mapFactory, java.util.stream.Collector<? super T,A,D> downstream)
Stream.collect(Collector)
with a
Collectors.groupingBy(Function, Supplier, Collector)
collector.static String join(java.util.stream.Stream<?> stream)
Stream.collect(Collector)
with a
Collectors.joining()
collector.static String join(java.util.stream.Stream<?> stream, CharSequence delimiter)
Stream.collect(Collector)
with a
Collectors.joining(CharSequence)
collector.static String join(java.util.stream.Stream<?> stream, CharSequence delimiter, CharSequence prefix, CharSequence suffix)
Stream.collect(Collector)
with a
Collectors.joining(CharSequence, CharSequence, CharSequence)
collector.Seq<T> filter(java.util.function.Predicate<? super T> predicate)
filter
in interface java.util.stream.Stream<T>
<R> Seq<R> map(java.util.function.Function<? super T,? extends R> mapper)
map
in interface java.util.stream.Stream<T>
java.util.stream.IntStream mapToInt(java.util.function.ToIntFunction<? super T> mapper)
mapToInt
in interface java.util.stream.Stream<T>
java.util.stream.LongStream mapToLong(java.util.function.ToLongFunction<? super T> mapper)
mapToLong
in interface java.util.stream.Stream<T>
java.util.stream.DoubleStream mapToDouble(java.util.function.ToDoubleFunction<? super T> mapper)
mapToDouble
in interface java.util.stream.Stream<T>
<R> Seq<R> flatMap(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends R>> mapper)
flatMap
in interface java.util.stream.Stream<T>
java.util.stream.IntStream flatMapToInt(java.util.function.Function<? super T,? extends java.util.stream.IntStream> mapper)
flatMapToInt
in interface java.util.stream.Stream<T>
java.util.stream.LongStream flatMapToLong(java.util.function.Function<? super T,? extends java.util.stream.LongStream> mapper)
flatMapToLong
in interface java.util.stream.Stream<T>
java.util.stream.DoubleStream flatMapToDouble(java.util.function.Function<? super T,? extends java.util.stream.DoubleStream> mapper)
flatMapToDouble
in interface java.util.stream.Stream<T>
Seq<T> distinct()
distinct
in interface java.util.stream.Stream<T>
Seq<T> sorted()
sorted
in interface java.util.stream.Stream<T>
Seq<T> sorted(Comparator<? super T> comparator)
sorted
in interface java.util.stream.Stream<T>
Seq<T> peek(java.util.function.Consumer<? super T> action)
peek
in interface java.util.stream.Stream<T>
Seq<T> limit(long maxSize)
limit
in interface java.util.stream.Stream<T>
Seq<T> skip(long n)
skip
in interface java.util.stream.Stream<T>
Seq<T> onClose(Runnable closeHandler)
onClose
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
void close()
close
in interface AutoCloseable
close
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
default Seq<T> sequential()
sequential
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
default Seq<T> parallel()
parallel
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
default Seq<T> unordered()
unordered
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
default Spliterator<T> spliterator()
spliterator
in interface java.util.stream.BaseStream<T,java.util.stream.Stream<T>>
spliterator
in interface Iterable<T>
default void forEach(java.util.function.Consumer<? super T> action)
forEach
in interface Iterable<T>
forEach
in interface java.util.stream.Stream<T>
Copyright © 2015. All Rights Reserved.