Slick select using value object (extending AnyVal)
<p>I am using Slick 2.1.0 with Scala 2.10.
I have a value object (<code>EMail</code>) that I map to a <code>VARCHAR</code> column.</p>

<pre><code>object EMail {
  import java.util.regex.Pattern
  val emailRegex = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE)

  val empty = EMail("x@y.com")
}

case class EMail(value: String) extends AnyVal with MappedTo[String] {
  def isValid: Boolean = EMail.emailRegex.matcher(value).find

  def validate: EMail = {
    assert(isValid)
    EMail(value.trim.toLowerCase)
  }

  override def toString = validate.value
}
</code></pre>

<p>The <code>Column</code> definition is:</p>

<pre><code>def email = column[Option[EMail]]("email_address")
</code></pre>

<p>This is my attempt at writing a finder:</p>

<pre><code>def findByEmail(email: Option[EMail]): Option[User] =
  database.withSession { implicit session: Session =&gt;
    queryAll.filter(e =&gt; e.email.isDefined &amp;&amp; e.email === email).firstOption
  }
</code></pre>

<p>This is the error message I get:</p>

<p><code>
[error] Users.scala:52: ambiguous implicit values:
[error]  both value BooleanCanBeQueryCondition in object CanBeQueryCondition of type =&gt; scala.slick.lifted.CanBeQueryCondition[Boolean]
[error]  and value BooleanOptionColumnCanBeQueryCondition in object CanBeQueryCondition of type =&gt; scala.slick.lifted.CanBeQueryCondition[scala.slick.lifted.Column[Option[Boolean]]]
[error]  match expected type scala.slick.lifted.CanBeQueryCondition[Nothing]
[error]     queryAll.filter(_.email === email.map(_.value)).firstOption
[error]                    ^
</code></p>