Java SE API

Function.andThen()

Runs this function before after. A thrown exception prevents subsequent evaluation; null after is rejected.

Formal Syntax & Structure

java syntaxjava
default <V> Function<T,V> andThen(Function<? super R,? extends V> after)

Parameters & Attributes

NameTypeDescription
afterFunction<? super R,? extends V>Transformation to run after this one; non-null

Return Value

Function<T,V>

Combined transformation

Working Example

Example Snippetjava
import java.util.*;import java.util.function.*;public class Main {
    public static void main(String[] args) {        Function<Integer, Integer> add = n -> n + 3;        Function<Integer, Integer> doubleIt = n -> n * 2;        System.out.println(add.andThen(doubleIt).apply(4));        System.out.println(add.compose(doubleIt).apply(4));    }}
Java Reference