I map a stream of NameValuePairs 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 Functions. 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 :
List<NameValuePair> newParamPairs = paramPairs.stream()
.flatMap((NameValuePair nvp) -> lookupFunction(nvp.getName()).stream().map(func -> func.apply(nvp)))
.flatMap(Collection::stream)
.collect(toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With