title: generic trait taking a class and it's companion object as a type parameter
body: <p>So I want to have a generic trait take as a type parameter a class with a companion object that inherits from a specific base class and refer to both the companion object and the class itself. So,</p>
  
  <pre><code>abstract class BaseModel[T] {
    def all: Seq[T]
  }
  
  case class Customer(email: String, password: String)
  
  object Customer extends BaseModel[Customer]
  
  // This trait is my issue
  trait BaseCrud[T] { 
    def table[T](f: T =&gt; String): String = {
      T.all.map(f _).mkString("")
    }
  }
  
  object Controller with BaseCrud {
    def foo = table(_.email)
  }
  </code></pre>
  
  <p>I had some solutions to that trait that were closer but I distilled it down so you can see what I am trying to do.</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>So I went with solution from Frank below, but I did manage to solve my initial puzzle. Though, in this case the solution was a bit ugly I'll include it here for completeness sake.</p>
  
  <pre><code>abstract class BaseModel[T] {
    def all: Seq[T] = Seq()
  }
  
  case class Customer(email: String, password: String)
  
  object Customer extends BaseModel[Customer]
  
  trait BaseCrud[T, U &lt;: BaseModel[T]] { 
    def table(f: T =&gt; String)(implicit obj: U): String = {
      obj.all.map(f(_)).mkString("")
    }
  }
  
  object Controller extends BaseCrud[Customer, Customer.type] {
    implicit val model = Customer
    def foo = table(_.email)
  }
  </code></pre>
  
  <p>So the type parameters changed to BaseCrud and the implicit was added to BaseCrud.table and implemented in Controller.model. I also fixed all my typos. I found it interesting Customer.type seems to be the type of the companion object.</p>