1 2 3 4 5 6 7 | function f(a, b, c) { return a + b + c; } function fa(b, c) { return f(1, b, c); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public class PartialFunctions { private static <T, U, R> Function<U, R> partialLeft(BiFunction<T, U, R> biFunction, T t) { return (u) -> biFunction.apply(t, u); } private static <T, U, R> Function<T, R> partialRight(BiFunction<T, U, R> biFunction, U u) { return (t) -> biFunction.apply(t, u); } public static void main(String[] args) { BiFunction<Integer, Integer, Integer> biFunction = (v1, v2) -> v1 - v2; Function<Integer, Integer> subtractFrom10 = partialLeft(biFunction, 10); Function<Integer, Integer> subtractBy10 = partialRight(biFunction, 10); System.out.println(subtractFrom10.apply(5)); // 5 System.out.println(subtractBy10.apply(5)); // -5 } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |