MumbleCloseable goes backward
Remi Forax
forax at univ-mlv.fr
Thu Jun 27 03:30:40 PDT 2013
sent again but with words in proper order (I hope :)
A Stream should not be AutoClosable or MaybeCloseable, or
MaybeMaybeNotCloseable ...
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, 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.
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 lambda as 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 MumbleCloseable.
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-observers
mailing list