Package dev.enola.common.function
Class MoreStreams
java.lang.Object
dev.enola.common.function.MoreStreams
Static utility methods related to
Stream instances. Streams has more.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,E extends Exception>
voidforEach(Stream<T> stream, CheckedConsumer<T, E> action) map(Stream<T> stream, CheckedFunction<T, R, E> mapper) Returns a stream consisting of the results of applying the given function to the elements of this stream, allowing the mapping function to throw a checked exception.static <T> CloseableIterable<T> toIterable(Stream<T> stream)
-
Method Details
-
toIterable
-
forEach
public static <T,E extends Exception> void forEach(Stream<T> stream, CheckedConsumer<T, E> action) throws E- Throws:
E
-
map
public static <T,R, Stream<R> mapE extends Exception> (Stream<T> stream, CheckedFunction<T, R, throws EE> mapper) Returns a stream consisting of the results of applying the given function to the elements of this stream, allowing the mapping function to throw a checked exception.This is an intermediate operation. The
mapperfunction is not executed, and no exception is thrown, until a terminal operation is invoked on the returned stream.- Type Parameters:
T- The type of the input elements of the streamR- The type of the output elements of the streamE- The type of the checked exception that can be thrown by the mapper- Parameters:
stream- the stream to mapmapper- a non-interfering, stateless function to apply to each element, which may throw a checked exception- Returns:
- the new stream
- Throws:
E- when a terminal operation is executed on the returned stream and the mapper throws a checked exception. Note that with parallel streams, the exception may (!) be wrapped in aRuntimeException.
-