I'm reading up on Java's Play framework but don't have much experience in Java. Can someone please explain this
Promise<Double> promiseOfPIValue = computePIAsynchronously();
Promise<Result> promiseOfResult = promiseOfPIValue.map(
new Function<Double,Result>() {
public Result apply(Double pi) {
return ok("PI value computed: " + pi);
}
}
);
I get that they're creating a promise promiseOfPiValue
that's supposed to compute a double asynchronously. Then, they call map
on that instance of promise to which they're passing a new instance of Function
as an argument, which has implemented a the apply
method.
The map part is where I get lost - how does the map method work? It looks like its returning a new promise of type Result
, but what's the logic of calling the apply
method inside an implementation of Function
?