Class MoreStreams

java.lang.Object
dev.enola.common.function.MoreStreams

public final class MoreStreams extends Object
Static utility methods related to Stream instances. Streams has more.
  • Method Details

    • toIterable

      public static <T> CloseableIterable<T> toIterable(Stream<T> stream)
    • 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, E extends Exception> Stream<R> map(Stream<T> stream, CheckedFunction<T,R,E> mapper) throws E
      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 mapper function 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 stream
      R - The type of the output elements of the stream
      E - The type of the checked exception that can be thrown by the mapper
      Parameters:
      stream - the stream to map
      mapper - 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 a RuntimeException.