Function<String,String> fc = Function.identity();
Function<String, String> stringStringFunction = fc.andThen(this::handleStra);
Function<String, String> stringStringFunction1 = fc.andThen(this::handleStrb);
Function<String, String> stringStringFunction2 = fc.andThen(this::handleStrc);
Function<String, String> reduce = Stream.of(stringStringFunction1, stringStringFunction1, stringStringFunction2).reduce(Function.identity(), Function::andThen);
System.out.println(stringStringFunction.compose(stringStringFunction1).apply("abc"));
System.out.println(stringStringFunction.apply("sss"));
System.out.println(reduce.apply("123"));
abcba
sssa
123bbc
public String handleStra(String s){
return s+"a";
}
public String handleStrb(String s){
return s+"b";
}
public String handleStrc(String s){
return s+"c";
}
标签:Function,andThen,String,stringStringFunction,模式,责任,fc,stringStringFunction1
From: https://www.cnblogs.com/Arborblog/p/17583518.html