package fun; /** * The function composition function. */ public class Compose extends Fun3,Fun,A,C> { public C apply (Fun f, Fun g, A x) { return compose(f, g, x); } /** * Applies compose to one argument. */ public static Fun2,A,C> compose (Fun f) { return new Compose().apply(f); } /** * Composes two functions * @param f The first function. * @param g The second function. * @return the functions that when applied to a value a will return * f(g(a)) */ public static Fun compose (Fun f, Fun g) { return new Compose().apply(f, g); } /** * Applies the composition of two functions to an argument. * @param f The first function. * @param g The second function. * @param a The value to apply the the composed function to. * @return f(g(a)) */ public static C compose (Fun f, Fun g, A a) { return f.apply(g.apply(a)); } }