You cannot do this “using a type system” because there is no way for a type system to guarantee that Future
will not fail, even if you promise it will not happen.
Consider this:
Future { doStuff(); } .recover { case _ => "Failed!" }
Even if you intend to make any further transformations impossible once Future
declared always successful, it still does not help, because the exception handler (or whatever you do to convert the original future to “always succeeding”) may throw.
Update: as indicated in the comment below, the above code snippet is incorrect: the .map
result does not match Future
as the .recover
result. However, the point of view. Here is the correct illustration:
Future { doStuff } .recover { case _ => Seq.empty[String].head }
source share