In my previous post I talked about replacing return List with a Consumer. There was a few comments on why not returning Stream. But those solution can cause resource leak if the Stream is not close.

s888marks pointed us to a solution that would solve the side effect and resource scoping issue used in the new StackWalker API.

<T, R> R getItems(Function<? super Stream<T>, ? extends R> f)

In that follow up post I’ll go through the code necessary to implement a classic list return, the function Stream and the Consumer.