I read on the Java Play platform, but do not have much experience working in Java. Can someone 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 understand that they are creating a promise promiseOfPiValue that should calculate double asynchronously. They then call map on this promise instance, to which they pass the new Function instance as the argument that the apply method implemented.
The part of the map where I get lost - how does the map method work? It looks like it is returning a new promise of type Result , but what is the logic of invoking the apply method inside the Function implementation?
source share