I found out that in order to pattern match Future fur Success/Failure, I need to use andThen (or onComplete, onSuccess...) and cannot use map. Why is that?
What I wanted to do (simplified, I am matching for Success and so on as well):
val f1 = Future(throw new Exception("Oops"))
f1 map { case Failure(e) => ??? }
Gives:
error: constructor cannot be instantiated to expected type;
found : scala.util.Failure[T]
required: Nothing
f1 map { case Failure(e) => ??? }
What I ended up doing:
val f1 = Future(throw new Exception("Oops"))
f1 andThen { case Failure(e) => ??? }
I would like to understand why map cannot be used here.