I map a stream of NameValuePair
s with a lookupFunction
(which returns a Function
), like this:
List<NameValuePair> paramPairs = getParamPairs();
List<NameValuePair> newParamPairs = paramPairs.stream()
.map((NameValuePair nvp) -> lookupFunction(nvp.getName()).apply(nvp))
.flatMap(Collection::stream)
.collect(toList());
But what if lookupFunction
returned a Collection<Function>
instead, and I wanted to perform a .map()
with each of the returned Function
s. How would I do that?
If
lookupFunction(nvp.getName())
returns a Collection of functions, you can get a Stream of that Collection and map each function to the result of applying it to the NameValuePair :