I have a Future[T] and I want to map the result, on both success and failure.
Eg, something like
val future = ... // Future[T]
val mapped = future.mapAll {
case Success(a) => "OK"
case Failure(e) => "KO"
}
If I use map
or flatmap
, it will only map successes futures. If I use recover
, it will only map failed futures. onComplete
executes a callback but does not return a modified future. Transform
will work, but takes 2 functions rather than a partial function, so is a bit uglier.
I know I could make a new Promise
, and complete that with onComplete
or onSuccess
/onFailure
, but I was hoping there was something I was missing that would allow me to do the above with a single PF.