-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathques-6-curry.java
More file actions
24 lines (20 loc) · 818 Bytes
/
Copy pathques-6-curry.java
File metadata and controls
24 lines (20 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
* QUESTION: curry(triFunction) — convert a 3-argument function into nested
* single-argument Function objects: Function<A,Function<B,Function<C,R>>>.
* Used by pro-1-java-utils for building small reusable pricing helpers.
*
* Input: curry(TaxCalc::apply).apply(100).apply(0.18).apply("INR")
* Output: computed tax value for that curried call chain
*/
import java.util.function.Function;
class Curry {
interface TriFunction<A, B, C, R> {
R apply(A a, B b, C c);
}
static <A, B, C, R> Function<A, Function<B, Function<C, R>>> curry(TriFunction<A, B, C, R> fn) {
throw new UnsupportedOperationException("TODO");
}
}
// --- TEST ---
// TriFunction<Integer, Integer, Integer, Integer> add3 = (a, b, c) -> a + b + c;
// System.out.println(Curry.curry(add3).apply(1).apply(2).apply(3)); // 6