Yコンビネータと言いつつZコンビネータじゃね?
Program.java
package example;
import java.util.function.*;
public class Program {
public static void main(String[] args) {
Function<Integer, Integer> fib
= Y(f -> n -> n > 1 ? f.apply(n - 1) + f.apply(n - 2) : n);
System.out.println(fib.apply(8));
}
static <A, R> Function<A, R> Y(
Function<Function<A, R>, Function<A, R>> f) {
Recursive<A, R> rec1 = r -> a -> f.apply(r.applyRec(r)).apply(a);
Recursive<A, R> rec2 = r -> a -> f.apply(r.applyRec(r)).apply(a);
return rec1.applyRec(rec2);
}
}
@FunctionalInterface
interface Recursive<A, R> {
public Function<A, R> applyRec(Recursive<A, R> f);
}