jOOQ / jOOL

jOOλ - The Missing Parts in Java 8 jOOλ improves the JDK libraries in areas where the Expert Group's focus was elsewhere. It adds tuple support, function support, and a lot of additional functionality around sequential Streams. The JDK 8's main efforts (default methods, lambdas, and the Stream API) were focused around maintaining backwards compatibility and implementing a functional API for parallelism.
http://www.jooq.org/products
Apache License 2.0
2.09k stars 168 forks source link

Suggestion - support autoclose #342

Closed saffih closed 6 years ago

saffih commented 6 years ago

Expected behavior and actual behavior:

Support autoclose specifically closing the underling stream once the stream is fully consumed (the provider of the stream protect it's side of the contract), the seq is handed over to a some other class that would not close it when it is fully consumed. Support deferred stream operations (for log, debug) and generation (extended seq).

Seq.of(1, 2, 3).onClose(()->{System.out.println("Done reading 1, 2, 3");}).autoclose() Updated Seq.java:597 added mthods: autoclose , append, prepend . (and appropriate unit tests.) https://github.com/saffih/jOOL/blob/seq-actions/jOOL-java-8/src/main/java/org/jooq/lambda/Seq.java

What your view with regard to that kind of extending seq ?

Thank Saffi

Steps to reproduce the problem:

Versions:

lukaseder commented 6 years ago

Unfortunately, this feature is not really easy to implement, because you can never really say if a stream is fully consumed. There's the Stream.iterator() method, which allows for consuming a stream item by item and discarding it prior to full consumption. Also, intercepting an exception from within the stream pipeline isn't easy. Typcially, those exceptions would also trigger a stream being "finished".

See also: