Skip to content

Commit 13f2eef

Browse files
committed
Fix Discounter examples
1 parent 77f1a97 commit 13f2eef

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎core-java/src/main/java/com/baeldung/strategy/Discounter.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
public interface Discounter extends UnaryOperator<BigDecimal> {
77

8+
default Discounter combine(Discounter after) {
9+
return value -> after.apply(this.apply(value));
10+
}
11+
812
static Discounter christmas() {
913
return (amount) -> amount.multiply(BigDecimal.valueOf(0.9));
1014
}

‎core-java/src/test/java/com/baeldung/strategy/StrategyDesignPatternUnitTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void shouldApplyAllDiscounts() {
5757

5858
final Discounter combinedDiscounter = discounters
5959
.stream()
60-
.reduce(v -> v, (d1, d2) -> (Discounter) d1.andThen(d2));
60+
.reduce(v -> v, Discounter::combine);
6161

6262
combinedDiscounter.apply(amount);
6363
}

0 commit comments

Comments
 (0)