title: Scala + Play -> Type mismatch; found : anorm.RowParser Required: anorm.ResultSetParser[Option[models.User]]
body: <p>SOLUTION:  I could not figure our how to return the non-exists for of Option[User] so in the case of not user found I create a dummy user object and reason on it from the controller (feels awful but working...):
  from Application.scala</p>
  
  <pre><code>val loginForm = Form(
  tuple(
    "email" -&gt; text,
    "password" -&gt; text
  ) verifying ("Invalid email or password", result =&gt; result match {
    case (email, password)  =&gt; (User.authenticate(email, password).map{_.id}.getOrElse(0) != 0)
  })
  </code></pre>
  
  <p>)</p>
  
  <p>AS OPPOSED TO:</p>
  
  <pre><code>val loginForm = Form(
    tuple(
    "email" -&gt; text,
    "password" -&gt; text
  ) verifying ("Invalid email or password", result =&gt; result match {
    case (email, password) =&gt; User.authenticate(email, password).isDefined
  })
  </code></pre>
  
  <p>)</p>
  
  <p>++++++++++++++++++ ORIGINAL 2 ++++++++++++++++++
  Thanks for the advice! I have made some change and seem to be getting closer however I can't figure out how to return an undefinded Option[user]. I have also tried case _ => null, See below:</p>
  
  <p>From User.scala</p>
  
  <pre><code>case class User(id: Int, email: String, name: String, password: String)
  
  object User {
  
    // -- Parsers
  
    /**
     * Parse a User from a ResultSet
     */
    val userParser = {
              get[Option[Int]]("uid")~        
              get[Option[String]]("email")~
              get[Option[String]]("fname")~
              get[Option[String]]("pbkval") map {
              case (uid~email~name~pbkval) =&gt; validate(uid,email, name, pbkval)
              }
    }
  
    /**
     * Retrieve a User from email.
     */
    def findByEmail(email: String): Option[User] = {
      DB.withConnection { implicit connection =&gt;
        SQL("select * from get_pbkval({email})").on(
                  'email -&gt; email         
              ).as(userParser.singleOpt)
      }
    }
  
  
    /**
     * Authenticated user session start.
     */
    def authenticate(email: String, password: String): Option[User] = {
      DB.withConnection { implicit connection =&gt;
        SQL(
              """
                          select * from get_pbkval({email})
              """
              ).on(
                  'email -&gt; email
              ).as(userParser.singleOpt)
  
          }
      }
  
    /**
     * Validate entry and create user object.
     */
      def validate(uid: Option[Int], email: Option[String], fname: Option[String], pbkval: Option[String]): User = {
                  val uidInt : Int = uid.getOrElse(0)
                  val emailString: String = email.getOrElse(null)
                  val fnameString: String = fname.getOrElse(null)
                  val pbkvalString: String = pbkval.getOrElse(null)
                  User(uidInt, emailString, fnameString, pbkvalString)
      }
  </code></pre>
  
  <p>I guess it is clear that I am not really getting something fundamental here.. I have read through <a href="http://www.playframework.org/modules/scala-0.9.1/anorm" rel="nofollow">http://www.playframework.org/modules/scala-0.9.1/anorm</a> and searched around for hours.. any help would be much appreciated! </p>