Skip to content

Commit e57024a

Browse files
committedDec 30, 2018
doc update
1 parent c04d85b commit e57024a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed
 

‎README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,33 @@ in books or on the internet.
5757
class Order {
5858
Cart cart;
5959
}
60-
```
60+
```
61+
1. it's often helpful to use currying(https://github.com/mtumilowicz/groovy-closure-currying)
62+
and functional interfaces to design API
63+
```
64+
@FunctionalInterface
65+
interface CurrableDoubleBinaryOperator extends DoubleBinaryOperator {
66+
67+
default DoubleUnaryOperator rate(double u) {
68+
return t -> applyAsDouble(t, u);
69+
}
70+
}
71+
```
72+
then we can easily implement conversion classes
73+
```
74+
class RateConverter implements CurrableDoubleBinaryOperator {
75+
76+
@Override
77+
public double applyAsDouble(double value, double rate) {
78+
return value * rate;
79+
}
80+
81+
static DoubleUnaryOperator milesToKmConverter() {
82+
return new RateConverter().rate(1.609);
83+
}
84+
85+
static DoubleUnaryOperator celsiusToFahrenheitConverter() {
86+
return new RateConverter().rate(1.8).andThen(x -> x + 32);
87+
}
88+
}
89+
```

0 commit comments

Comments
 (0)
Failed to load comments.