twirl icon indicating copy to clipboard operation
twirl copied to clipboard

Support for Type Parameters

Open tilmanrossmy opened this issue 8 years ago • 4 comments

At the moment it is only possible to use Type classes with a wildcard, thus loosing all type information

@import TypedCaseClass
 @(typedCaseClass: TypedCaseClass[_])(implicit request: RequestHeader, 
  messages: Messages){
   //...
 }

It would be nice, if something like this would be possible:

@import TypedCaseClass
 @[T](typedCaseClass: TypedCaseClass[T])(implicit request: RequestHeader, 
  messages: Messages){
   //...
 }

tilmanrossmy avatar Sep 29 '17 13:09 tilmanrossmy

Would be an interesting feature if someone wants to implement it.

gmethvin avatar Dec 02 '17 08:12 gmethvin

The biggest roadblock I see for this are the TemplateN traits that have the abstract render methods. For example:

trait Template1[A, Result] {
  def render(a: A): Result
}

It seems like render is mostly a Play-Java thing, as I've rarely (if ever) have seen it used from Scala code, and unless I'm mistaken, it seems like an alias to apply, with the exception that it's required by these template traits, where apply actually isn't. Anyway, the issue arises where if we want a template with this signature:

@[A](list: List[A])

It should compile to have an apply method that looks like

def apply[A](list: List[A]): Html

But then render also needs to include the type parameter A in it's signature to call apply, but it can't because then the signature required by Template1 would be left unimplemented. I was able to get some basic examples working by cutting out the TemplateN traits, but this is a pretty big API change, so I can't really proceed without some guidance.

mhzajac avatar Jun 13 '18 13:06 mhzajac

Also see #37

mkurz avatar Nov 10 '18 00:11 mkurz