diff --git a/5-0-functional-programming/5-1-1-crazy-lambdas/src/main/java/com/bobocode/fp/CrazyLambdas.java b/5-0-functional-programming/5-1-1-crazy-lambdas/src/main/java/com/bobocode/fp/CrazyLambdas.java index 86812db5..6345d14f 100644 --- a/5-0-functional-programming/5-1-1-crazy-lambdas/src/main/java/com/bobocode/fp/CrazyLambdas.java +++ b/5-0-functional-programming/5-1-1-crazy-lambdas/src/main/java/com/bobocode/fp/CrazyLambdas.java @@ -265,7 +265,7 @@ public static BiFunction, String, IntUnaryOperator * @return a comparator instance */ public static > Comparator comparing(Function mapper) { - return (o1, o2) -> mapper.apply(o1).compareTo(mapper.apply(o2)); + return Comparator.comparing(mapper); } /** @@ -285,13 +285,7 @@ public static > Comparator comparing(Funct */ public static > Comparator thenComparing( Comparator comparator, Function mapper) { - return (o1, o2) -> { - var initialResult = comparator.compare(o1, o2); - if (initialResult != 0) { - return initialResult; - } - return mapper.apply(o1).compareTo(mapper.apply(o2)); - }; + return (o1,o2) -> comparator.compare(o1,o2) == 0 ? mapper.apply(o1).compareTo(mapper.apply(o2)) : comparator.compare(o1,o2); } /**