MumbleCloseable goes backward

Remi Forax forax at univ-mlv.fr
Thu Jun 27 03:19:44 PDT 2013


A Stream should be AutoClosable or MaybeCloseable, or 
MaybeMaybeNotCloseable ...
because using a TWR here goes in the wrong direction, the Stream API is 
fluent, from left to right and
the TWR is right to left because you have to declare a local variable 
and type it (again unlike the Stream API).

So instead of:
   try (Stream<Path> stream = Files.walkFile(directory)) {
     stream.forEach(path -> {
        ...
     });
   }
which is an external way to manage the resources.

Because we have lambda, we should promote the internal way to manage the 
resources, like the rest of the Stream API,
so walkFile should be written to take a Function<Stream, R>, like this:
   Files.walkFile(directory, stream -> stream.forEach(path -> {
     ...
   });
with the TWR written around the call to the function inside walkFile.

so there is *no need* for a Mumble Closeable.

Rémi


On 06/25/2013 03:04 AM, Brian Goetz wrote:

[...]

>   try (Stream s = list.stream().filter(...).map(...)) {
>     s.forEach(...);
>   }
>
> instead of
>
>   list.stream()
>       .filter(...)
>       .map(...)
>       .forEach(...);
>



More information about the lambda-libs-spec-experts mailing list