[patch] Function.compose()/andThen() vs BiFunction.compose() (original) (raw)
Jürgen Kreileder jk at blackdown.de
Wed Apr 3 08:45:21 PDT 2013
- Previous message: Type inference problem with JDK 8 Build 82
- Next message: [patch] Add missing @throws to methods using Objects.requireNonNull()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Rename BiFunction.compose() to BiFunction.andThen() to bring it in line with recent changes in Function.
- Consolidate documentation
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);
/**
* Combine with another function producing a function which performs
both
* operations.
* Compose a new function which applies this function followed by the
* provided function. * * @param <W> Type of output objects from the combined function. May
be the
* same type as {@code <U>}.
* same type as {@code <T>}, {@code <U>}, or {@code <R>}. * @param after An additional function to be applied to the result of
this * function.
* @return A function which performs both the original function
followed by
* a second function.
* @return A function which performs this function followed by the
provided
* function
* @throws NullPointerException if after is null */
- public default BiFunction<T, U, W> compose(Function<? super R, ?
extends W> after) {
- default BiFunction<T, U, W> andThen(Function<? super R, ? extends
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 */
- public R apply(T t);
R apply(T t);
/**
- Compose a new function which applies the provided function before
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)); }
- Previous message: Type inference problem with JDK 8 Build 82
- Next message: [patch] Add missing @throws to methods using Objects.requireNonNull()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]