almost.functional.utils
T
- public final class Stream<T> extends java.lang.Object implements java.io.Closeable
Modifier and Type | Method and Description |
---|---|
boolean |
allMatch(Predicate<? super T> predicate)
Returns whether all elements of this stream match the provided predicate.
|
boolean |
anyMatch(Predicate<? super T> predicate)
Returns whether any elements of this stream match the provided predicate.
|
void |
close() |
static <T> Stream<T> |
concat(Stream<? extends T> a,
Stream<? extends T> b)
Creates a concatenated stream whose elements are all the elements of the first stream followed by all the elements of the second stream.
|
long |
count()
The element count in the stream.
|
Stream<T> |
filter(Predicate<? super T> predicate)
Returns a stream consisting of the elements of this stream that match the given predicate.
|
void |
forEach(Consumer<? super T> action)
Performs an action for each element of this stream.
|
<R> Stream<R> |
map(Function<? super T,? extends R> mapper)
Returns a stream consisting of the results of applying the given function to the elements of this stream.
|
boolean |
noneMatch(Predicate<? super T> predicate)
Returns whether no elements of this stream match the provided predicate.
|
static <R> Stream<R> |
of(java.lang.Iterable<R> iterable)
Create a new stream of the elements that the iterable.iterator() will yield
|
static <R> Stream<R> |
of(java.util.Iterator<R> iterator)
Create a stream based on an iterator.
|
static <R> Stream<R> |
of(R... elements)
Create a stream of the elements provided.
|
Stream<T> |
onClose(java.lang.Runnable closeHandler)
Add Runnables to run when the stream closes.
|
Optional<T> |
reduce(BiFunction<T,? super T,T> accumulator)
Performs a reduction on the elements of the stream, using an accumulation function, and returns an Optional describing the reduced value, if any.
|
<R> R |
reduce(R initial,
BiFunction<R,? super T,R> accumulator)
Performs a reduction on the elements of this stream, using the provided initial value and accumulation functions.
|
public static <R> Stream<R> of(java.lang.Iterable<R> iterable)
R
- the type of the resultant stream's elementsiterable
- the source of the iteratorpublic static <R> Stream<R> of(R... elements)
R
- type of elementselements
- elements of the new streampublic static <R> Stream<R> of(java.util.Iterator<R> iterator)
R
- type of elementsiterator
- the iteratorpublic void forEach(Consumer<? super T> action)
action
- an action to perform on the elementspublic Optional<T> reduce(BiFunction<T,? super T,T> accumulator)
accumulator
- an associative function for combining two valuespublic <R> R reduce(R initial, BiFunction<R,? super T,R> accumulator)
R
- return typeinitial
- the initial valueaccumulator
- the acummulation functionpublic Stream<T> filter(Predicate<? super T> predicate)
predicate
- to apply to each element to determine if it should be includedpublic <R> Stream<R> map(Function<? super T,? extends R> mapper)
R
- The element type of the new streammapper
- function to apply to each elementpublic boolean anyMatch(Predicate<? super T> predicate)
predicate
- to apply to elements of this streampublic boolean noneMatch(Predicate<? super T> predicate)
predicate
- to apply to elements of this streampublic boolean allMatch(Predicate<? super T> predicate)
predicate
- to apply to elements of this streampublic long count()
public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)
T
- type of elementsa
- first streamb
- second streampublic Stream<T> onClose(java.lang.Runnable closeHandler)
closeHandler
- a Runnablepublic void close() throws java.io.IOException
close
in interface java.io.Closeable
java.io.IOException