Skip to content

Commit

Permalink
#19 Use collectMap instead of collectList in collectCountResults
Browse files Browse the repository at this point in the history
  • Loading branch information
jameschen authored and jameschen committed Oct 28, 2019
1 parent 57ffbc3 commit 3c56241
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.function.Function;

import static im.turms.turms.common.Constants.*;

Expand Down Expand Up @@ -243,14 +244,9 @@ public static ResponseEntity authenticated(Boolean data) {

public static <T> Mono<ResponseEntity> collectCountResults(List<Mono<Pair<String, T>>> counts) {
Mono<Map<String, T>> resultMono = Flux.merge(counts)
.collectList()
.map(pairs -> {
Map<String, T> resultMap = new HashMap<>(counts.size());
for (Pair<String, T> pair : pairs) {
resultMap.put(pair.getLeft(), pair.getRight());
}
return resultMap;
});
.collectMap(
(Function<? super Pair<String, T>, String>) Pair::getLeft,
(Function<? super Pair<String, T>, T>) Pair::getRight);
return okWhenTruthy(resultMono);
}
}

0 comments on commit 3c56241

Please sign in to comment.