0
0

More than 1 year has passed since last update.

Function interface andThen method, compose method

Posted at

f1.andThen(f2)は、f1,f2
f1.compose(f2)は、f2,f1

下記の例
fc1 integer→string, string→integer
fc2 string→integer, integer→string

public class Outer {
    public static void main(String[] args) {
        Function<Integer, String> f1 = x -> String.valueOf(x + 2);
        Function<String, Integer> f2 = x -> Integer.valueOf(x) * 2;
        Function<Integer, Integer> fc1 = f1.andThen(f2);
        System.out.println(fc1.apply(5));
        System.out.println(f1.andThen(f2).apply(5));
        Function<String, String> fc2 = f1.compose(f2);
        System.out.println(fc2.apply("5"));
        System.out.println(f1.compose(f2).apply("5"));
    }
14
14
12
12
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0