title: Scala: type mismatch; found : scala.concurrent.Future[Option[models.Account]] required: Option[?]
body: <p>Give then following code:</p>
  
  <p><code>AccountsDAO.scala:</code></p>
  
  <pre><code>def find(id: EntityId): Future[Option[Account]] =
      collection.find(Json.obj(Fields.Id -&gt; id)).one[Account]
  </code></pre>
  
  <p>And <code>AccountService.scala:</code></p>
  
  <pre><code>def getAccount(id: Option[Credentials]) = id.flatMap {
      accountId =&gt; accountDAO.find(accountId.accountId) //Throws an error
    }
  </code></pre>
  
  <p>The commented line above throws this error:</p>
  
  <pre><code>type mismatch; found : scala.concurrent.Future[Option[models.Account]] required: Option[?]
  </code></pre>
  
  <p>What am I missing? Why does flattop return an <code>Option[?]</code>. If I change the return type of the <code>getAccount</code> method as:</p>
  
  <pre><code>  def getAccount(id: Option[Credentials]): Future[Option[Account]] = id.flatMap {
      accountId =&gt; accountDAO.find(accountId.accountId) //Still throws an error
    }
  </code></pre>
  
  <p>I get the error below:</p>
  
  <pre><code>type mismatch; found : Option[Nothing] required: scala.concurrent.Future[Option[models.Account]]
  </code></pre>
  
  <p>What is going on? What am I missing?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Edit</strong> : Here's the code in the controller and what I'm trying to do:</p>
  
  <pre><code>  def auth = Action.async(parse.json) { request =&gt;
      {
  
        val authRequest = request.body.validate[AuthRequest]
        authRequest.fold(
          errors =&gt; Future(BadRequest),
          auth =&gt; {
            //First verify username and password
            val authRequestResult = for {
              validCredentials &lt;- credentialsManager.checkEmailPassword(auth.email, auth.password)
              account:Option[Account] &lt;- accountManager.getAccount(validCredentials)
              session:Session &lt;- sessionManager.createSession(account.get.id, account.get.roles)
  
              touchedSession &lt;- sessionManager.TouchSession(session.id)
  
            } yield AuthResponse(session.id, session.token, account.get.id, account.get.roles)
  
            authRequestResult map {
              case res: AuthResponse =&gt; Ok(Json.toJson(res))
              case _ =&gt; NotFound
  
            }
          })
      }
    }
  </code></pre>
  
  <p>The checkEmailPassword method above returns a Future[Option]:</p>
  
  <pre><code>def checkEmailPassword(email: String, password: String) =
      for {
        credentials &lt;- credentialsDAO.find(AuthType.EmailPassword, email)
        validPassword &lt;- BCrypt.checkFuture(password, credentials)
  
      } yield (credentials)
  </code></pre>
  
  <p>And <code>credentialsDAO.find:</code></p>
  
  <pre><code>def find(authType: AuthType.Value, authAccountId: String) =
      collection.find(
        Json.obj(Fields.AuthType → authType,
          Fields.AuthAccountId → authAccountId)).one[Credentials].recover(wrapLastError)
  </code></pre>
  
  <p>So when <code>checkEmailPassword</code> returns an Option[Credentials] object, is it okay to assume the <code>for comprehension</code> in the controller will not execute any further if it returns a <code>None</code>? Then I could just say something like <code>account:Option[Account] &lt;- accountManager.getAccount(validCredentials.get.id)</code>. Is there a better way to structure/organize this code? Any patterns that I can follow/use?</p>