File tree Expand file tree Collapse file tree
src/main/java/io/github/aplotnikov/java_8_misuses/stream/collectors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package io .github .aplotnikov .java_8_misuses .stream .collectors ;
22
33import io .github .aplotnikov .java_8_misuses .domain .Client ;
4+ import io .github .aplotnikov .java_8_misuses .utils .Annotations .Bad ;
45
56import java .util .List ;
67
78import static io .github .aplotnikov .java_8_misuses .utils .Annotations .Good ;
89import static io .github .aplotnikov .java_8_misuses .utils .Annotations .Ugly ;
910import static java .util .Comparator .comparingInt ;
11+ import static java .util .function .BinaryOperator .maxBy ;
1012
1113class TrueFunctionalApproach {
1214 @ Ugly
@@ -48,6 +50,15 @@ Client findTheOldestClient(List<Client> clients) {
4850 }
4951 }
5052
53+ @ Bad
54+ class StreamsWithReductionAndMax {
55+ Client findTheOldestClient (List <Client > clients ) {
56+ return clients .stream ()
57+ .reduce (maxBy (comparingInt (Client ::getAge )))
58+ .orElse (null );
59+ }
60+ }
61+
5162 @ Good
5263 class MaxWithComparator {
5364 Client findTheOldestClient (List <Client > clients ) {
You can’t perform that action at this time.
0 commit comments