Package panda.std.stream
Class PandaStream<T>
java.lang.Object
panda.std.stream.PandaStream<T>
- Type Parameters:
T-
- All Implemented Interfaces:
AutoCloseable
Simple wrapper to combine standard
Stream API with wrappers like
Option or Result, and some extra features.
Most methods are lazy evaluated as in Stream API, but some of them are not!
In most cases it shouldn't be a problem, but for huge sets or performance sensitive use-cases
you should be aware of methods you use, especially these based on duplicate() feature.-
Method Summary
Modifier and TypeMethodDescriptionany()<R> PandaStream<Pair<T,R>> associateWith(R value) voidclose()<A,R> R concat(PandaStream<T> pandaStream) final PandaStream<T>longcount()longdistinct()Simulates the stream duplication mechanism.static <T> PandaStream<T>empty()<E> Result<PandaStream<T>,E> filterToResult(Function<? super T, Option<E>> predicate) <R> Option<R>findIterating(Function<? super T, Option<R>> predicate) <R> PandaStream<R><R> PandaStream<R>flatMapStream(Function<T, Stream<R>> function) <A,R> PandaStream<R> flatMapWith(A with, BiFunction<A, T, Iterable<R>> function) <E> Result<PandaStream<T>,E> forEachByResult(Function<T, Option<E>> predicate) head()<S> PandaStream<S>iterator()last()<R> PandaStream<R><R> PandaStream<R><A,R> PandaStream<R> mapWith(A with, BiFunction<A, T, R> function) static <T> PandaStream<T>static <T> PandaStream<T>of(Collection<T> collection) static <T> PandaStream<T>static <T> PandaStream<T>of(T... array) Find first element in stream or return all failures.skip(long n) sorted()sorted(Comparator<? super T> comparator) <R> PandaStream<R><E extends Exception>
PandaStream<T>throwIfNot(Predicate<T> condition, Function<T, E> exception) T[]toArray(IntFunction<T[]> function) toList()<K,V> Map<K, V> <K,V> Map<K, V> <K,V> Map<K, V> toMapByPair(Function<T, Pair<K, V>> mapper) <K,V> Map<K, V> toSet()toStream()<R> PandaStream<R>
-
Method Details
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
stream
-
concat
-
concat
-
concat
-
concat
-
associateWith
-
transform
-
map
-
mapWith
-
mapOpt
-
flatMap
-
flatMapWith
-
flatMapStream
-
is
-
isNot
-
filter
-
filterNot
-
filterToResult
-
search
Find first element in stream or return all failures. The size of list with errors may be equal to number of all elements in stream, so it shouldn't be used with large datasets.- Type Parameters:
R- type of matched elementE- type of failures- Parameters:
searchFunction- search function may return success (matched element, terminates stream) or failure (to continue searching).- Returns:
- result with matched element or list of failures
-
distinct
-
sorted
-
sorted
-
skip
-
find
-
head
-
last
-
any
-
count
-
count
public long count() -
collect
-
throwIfNot
-
takeWhile
-
forEach
-
forEachByResult
-
findIterating
-
duplicate
Simulates the stream duplication mechanism. The method transforms current stream into buffered list of elements and then recreates current stream and the duplicated one on top of that. This method should not be used to handle huge sets and may be a bottleneck if called often.- Returns:
- duplicated stream
-
toArray
-
toList
-
toSet
-
toMap
-
toMap
-
toMapByPair
-
toMapByPair
-
toStream
-
iterator
-
of
-
of
-
of
-
of
-
empty
-