title: Scala implicit conversion for object
body: <p>Suppose that I have the following code snippet:</p>
  
  <pre><code>import scala.language.implicitConversions
  
  sealed trait Command {
    val typeName: String
  }
  
  object Command {
  
    implicit def command2String(implicit c: Command): String =
      c.typeName
  
  }
  
  case object SendMessageCommand extends Command {
    override val typeName: String = "send_message"
  }
  </code></pre>
  
  <p>I would like to compare <code>String</code> with <code>Command</code> descendants without explicit conversion. For example:</p>
  
  <pre><code>"sendMessage" == SendMessageCommand
  </code></pre>
  
  <p>Q1: Is it possible in Scala?</p>
  
  <p>Q2: Can I define generic implicit conversion that will convert known type such as String to super class types (like <code>Command</code> in my case)?</p>
  
  <p>For example:</p>
  
  <pre><code>implicit def string2Command(implicit s: String): Command = {
    case "send_message" =&gt; SendMessageCommand
    case _ =&gt; // some error thrown
  }
  </code></pre>
  
  <p>P.S. I know that it is not idiomatic Scala, but it would be awesome to find out the right way.</p>