//example 1 assignment
Function<String,String> postfixFunction = s -> s + "-postfix";
//example 2 passing as parameter
public void someMethod() {
stringManipulator(postfixFunction, asList("A","B"));
}
A higher order function is a function that accepts other functions as arguments, or returns another function.
//example 1 accepting function as arguments
public List<String> stringManipulator(Function<String, String> manipulator, List<String> data) {
return data.stream().map(manipulator).collect(toList());
}
//example 2 returning a function
public Function<String, String> postfixFunction() {
return s -> s + "-postfix";
}
No comments:
Post a Comment