What is the best practice for flatMap replacment

Brian Goetz brian.goetz at oracle.com
Tue Apr 9 14:59:57 PDT 2013


In a few days, you'll have:

   Streams.singleton(e)

and

   new StreamBuilder()

to help you along.

On 4/9/2013 5:31 PM, Boaz Nahum wrote:
> My old code:
>
> public void flattenInto(T element, Consumer<R> sink) {
> R r = ..
> if (...) { sink.accept(r);
> }
>
> Is replaced with:
>
> Stream<? extends R> apply(T element) {
>                        R r = ...
> return ?  (...) :  Collections.singleton(t).stream() : null;
> }
>
> I wonder if I can do better.
>
> Thanks
> Boaz
>


More information about the lambda-dev mailing list