1 2 3 4 5 6 7 8 9 10 11 12 13 | Function3< Integer, Integer, Integer, Integer> function3 = (v1, v2, v3) -> (v1 + v2) * v3; Function3< Integer, Integer, Integer, Integer> composed = function3.andThen(v -> v * 100); int result = composed.apply(1, 2, 3); System.out.println(result); // 输出结果 900 Function1< String, String> function1 = String::toUpperCase; Function1< Object, String> toUpperCase = function1.compose(Object::toString); String str = toUpperCase.apply(List.of("a", "b")); System.out.println(str); // 输出结果[A, B] |
1 2 3 4 5 6 | Function4< Integer, Integer, Integer, Integer, Integer> function4 = (v1, v2, v3, v4) -> (v1 + v2) * (v3 + v4); Function2< Integer, Integer, Integer> function2 = function4.apply(1, 2); int result = function2.apply(4, 5); System.out.println(result); // 输出 27 |
1 2 3 4 5 | Function3<Integer, Integer, Integer, Integer> function3 = (v1, v2, v3) -> (v1 + v2) * v3; int result = function3.curried().apply(1).curried().apply(2).curried().apply(3); System.out.println(result); |
1 2 3 4 5 6 7 8 | Function2<BigInteger, Integer, BigInteger> pow = BigInteger::pow; Function2<BigInteger, Integer, BigInteger> memoized = pow.memoized(); long start = System.currentTimeMillis(); memoized.apply(BigInteger.valueOf(1024), 1024); long end1 = System.currentTimeMillis(); memoized.apply(BigInteger.valueOf(1024), 1024); long end2 = System.currentTimeMillis(); System.out.printf("%d ms -> %d ms", end1 - start, end2 - end1); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |