--- old/src/share/classes/java/util/function/Function.java 2013-05-06 18:47:02.767524283 -0700 +++ new/src/share/classes/java/util/function/Function.java 2013-05-06 18:47:02.567524275 -0700 @@ -24,14 +24,15 @@ */ package java.util.function; +import java.util.Objects; /** * Apply a function to the input argument, yielding an appropriate result. A * function may variously provide a mapping between types, object instances or * keys and values or any other form of transformation upon the input. * - * @param the type of the input to the {@code apply} operation. - * @param the type of the result of the {@code apply} operation. + * @param the type of the input to the {@code apply} operation + * @param the type of the result of the {@code apply} operation * * @since 1.8 */ @@ -44,5 +45,48 @@ * @param t the input object * @return the function result */ - public R apply(T t); + R apply(T t); + + /** + * Compose a new function which applies the provided function followed by + * this function. + * + * @param Type of input objects to the combined function. May be the + * same type as {@code } or {@code } + * @param before An additional function to be applied before this function + * is applied + * @return A function which performs the provided function followed by this + * function + * @throws NullPointerException if before is null + */ + default Function compose(Function before) { + Objects.requireNonNull(before); + return (V v) -> apply(before.apply(v)); + } + + /** + * Compose a new function which applies this function followed by the + * provided function. + * + * @param Type of output objects to the combined function. May be the + * same type as {@code } or {@code } + * @param after An additional function to be applied after this function is + * applied + * @return A function which performs this function followed by the provided + * function followed + * @throws NullPointerException if after is null + */ + default Function andThen(Function after) { + Objects.requireNonNull(after); + return (T t) -> after.apply(apply(t)); + } + + /** + * Returns a {@code Function} whose {@code apply} method returns its input. + * + * @param the type of the input and output objects to the function + */ + static Function identity() { + return t -> t; + } }