package fun; import java.util.Iterator; /** * Abstract class for unary functions. */ public abstract class Fun { /** * Should be overridden by subclasses to apply the function. * * @param x The function parameter. * @return The result of the function */ public abstract B apply (A x); /** * Composes this function with another function. * f.compose(g).apply(x) is equivalent to * f.apply(g.apply(x)) * * @param f The function to compose this function with * @return The composed function */ public Fun compose (final Fun f) { return Compose.compose(this, f); } /** * Applies this function to all the element returned by an iterator. * */ public Iterator map(Iterator xs) { return Map.map(this, xs); } /** * Convenience method, same as map(xs.iterator()). */ public Iterator map (Iterable xs) { return map(xs.iterator()); } }