MumbleCloseable goes backward

Paul Sandoz paul.sandoz at oracle.com
Thu Jun 27 03:38:10 PDT 2013


On Jun 27, 2013, at 12:19 PM, Remi Forax <forax at univ-mlv.fr> wrote:

> 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 could be Stream.

- ain't gonna work for flatMap:

  Files.walk(dir, sp-> sp.flatMap(p -> Files.lines(p, Function.identity()))...);

- much harder to read than:

  Files.walk(dir).flatMap(Files::lines)...

Paul.


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