[patch] Function.compose()/andThen() vs BiFunction.compose() (original) (raw)

Jürgen Kreileder jk at blackdown.de
Wed Apr 3 08:45:21 PDT 2013


Since http://hg.openjdk.java.net/lambda/lambda/jdk/rev/fa66ee11db44 and http://hg.openjdk.java.net/lambda/lambda/jdk/rev/62d2a1511961Function.compose() and BiFunction.compose() have different semantics. The following patch renames BiFunction.compose() to BiFunction.andThen() to bring the two interfaces in line again. It also fixes a few JavaDoc errors.

(Btw, the code sometimes uses the superfluos public modifier in interfaces and sometimes it doesn't. IMHO it should be removed everywhere - at least it should be consistent.)

HG changeset patch

User Jürgen Kreileder <jk at blackdown.de>

Date 1365001269 -7200

Node ID b6327bd4e9a27d6157e772c845ce1909d2dc0a43

Parent eb415ba1d51bbb6478e55ba20ac882f3dafc6de2

diff --git a/src/share/classes/java/util/function/BiFunction.java b/src/share/classes/java/util/function/BiFunction.java --- a/src/share/classes/java/util/function/BiFunction.java +++ b/src/share/classes/java/util/function/BiFunction.java @@ -52,17 +52,18 @@ R apply(T t, U u);

 /**

both

be the

this * function.

followed by

provided

extends W> after) {

W> after) { Objects.requireNonNull(after); return (T t, U u) -> after.apply(apply(t, u)); } diff --git a/src/share/classes/java/util/function/Function.java b/src/share/classes/java/util/function/Function.java --- a/src/share/classes/java/util/function/Function.java +++ b/src/share/classes/java/util/function/Function.java @@ -45,7 +45,7 @@ * @param t the input object * @return the function result */

this @@ -57,9 +57,9 @@ * applied * @return A function which performs the provided function followed by this * function - * @throws NullPointerException if inner is null + * @throws NullPointerException if before is null */ - public default Function<V, R> compose(Function<? super V, ? extends T> before) { + default Function<V, R> compose(Function<? super V, ? extends T> before) { Objects.requireNonNull(before); return (V v) -> apply(before.apply(v)); } @@ -70,13 +70,13 @@ * * @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 before this function is - * applied - * @return A function which performs the provided function followed by this + * @param after An additional function to be applied to the result of this + * function + * @return A function which performs this function followed by the provided * function * @throws NullPointerException if after is null */ - public default Function<T, V> andThen(Function<? super R, ? extends V> after) { + default Function<T, V> andThen(Function<? super R, ? extends V> after) { Objects.requireNonNull(after); return (T t) -> after.apply(apply(t)); }



More information about the lambda-dev mailing list