A for understanding is just syntactic sugar for the chain foreach , map , flatMap , filter , etc. When you write if account.isConfirmed , this is equivalent to using the Future filter method.
The meaning of the permitted Future is contained in Try, which can either take the form of Success or Failure. (Compare this with Option, which can take the form of Some or None.)
It appears that the Option filter converts Some to None, if the contained value does not give a predicate, the Future / Try filter methods convert success to failure. If you look at an implementation of Future.filter or Try.filter , this is done by returning a failure with a new NoSuchElementException containing the predicate is not satisfied that you mentioned.
Thus, the error message itself is entirely in design and corresponds to the type system. Any step in understanding will only project another Future, so the if account.isConfirmed entry will either project Success if it passes the filter or Fails if it is not.
This is the answer to why Scala will not change the Future [Result] into the Future [Variant [Result]] when you use if / filter . If you would like to have a successful Future containing Option or an empty Seq, you must do it explicitly (as shown in Jean Logeart and Alvaro Carrasco's Answers ).
source share