What is the best practice for flatMap replacment

Boaz Nahum boaznahum at gmail.com
Tue Apr 9 14:31:46 PDT 2013


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