I can\'t get my head around the difference between thenApply() and thenCompose().
So, could someone provide a valid use case?
Fro
The updated Javadocs in Java 9 will probably help understand it better:
CompletionStage thenApply(Function super T,? extends U> fn)
Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied function.
This method is analogous to Optional.map and Stream.map.
See the CompletionStage documentation for rules covering exceptional completion.
CompletionStage thenCompose(Function super T,? extends CompletionStage> fn)
Returns a new CompletionStage that is completed with the same value as the
CompletionStagereturned by the given function.When this stage completes normally, the given function is invoked with this stage's result as the argument, returning another
CompletionStage. When that stage completes normally, theCompletionStagereturned by this method is completed with the same value.To ensure progress, the supplied function must arrange eventual completion of its result.
This method is analogous to Optional.flatMap and Stream.flatMap.
See the CompletionStage documentation for rules covering exceptional completion.