After looking several answers on how to merge maps in stream, it seems that all answers so far suggest the "flatten and collect" method:
Map<String, Double> outMap =
myCol.stream()
.flatMap(m -> m.entrySet().stream())
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue, Double::sum));
But why not use reducing to merge:
Map<String, Double> outMap =
myCol.stream()
.reduce((r, r1) -> {
r1.forEach((k, v) -> r.merge(k, v, Double::sum))
}
.orElseThrow(()->Exception());
Is there any drawback or issue with the reducing method?