package fun; /** * A binary function that simply returns its first argument. To get a * function that returns its second argument, use: * new Const().flip() */ public class Constant extends Fun2 { /** * Returns the first argument. That is, * new Const().apply(x,y) == x is true. * * @param x The first argument * @param y The second argument * @return x */ public A apply(A x, B y) { return constant(x, y); } /** * Creates a constant function. * * @return A function that will return x, whatever argument it is * applied to. */ public static Fun constant(A x) { return new Constant().apply(x); } /** * Applies the constant function. */ public static A constant(A x, B y) { return x; } }