Fix Discounter examples
This commit is contained in:
parent
77f1a97e8f
commit
13f2eef879
|
@ -5,6 +5,10 @@ import java.util.function.UnaryOperator;
|
|||
|
||||
public interface Discounter extends UnaryOperator<BigDecimal> {
|
||||
|
||||
default Discounter combine(Discounter after) {
|
||||
return value -> after.apply(this.apply(value));
|
||||
}
|
||||
|
||||
static Discounter christmas() {
|
||||
return (amount) -> amount.multiply(BigDecimal.valueOf(0.9));
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class StrategyDesignPatternUnitTest {
|
|||
|
||||
final Discounter combinedDiscounter = discounters
|
||||
.stream()
|
||||
.reduce(v -> v, (d1, d2) -> (Discounter) d1.andThen(d2));
|
||||
.reduce(v -> v, Discounter::combine);
|
||||
|
||||
combinedDiscounter.apply(amount);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue