import java.util.function.Function; @FunctionalInterface interface SelfApplicable { OUTPUT apply(SelfApplicable input); } class Utils { public static SelfApplicable, Function>, Function>> y(Class input, Class output) { return y -> f -> x -> f.apply(y.apply(y).apply(f)).apply(x); } public static Function, Function>, Function> fix(Class input, Class output) { return y(input, output).apply(y(input, output)); } public static long fib(int m) { if (m < 0) throw new IllegalArgumentException("n can not be a negative number"); return fix(Integer.class, Long.class).apply( f -> n -> (n < 2) ? n : (f.apply(n - 1) + f.apply(n - 2)) ).apply(m); } }