New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no type arguments for views? #37

Open
benmccann opened this Issue Jul 31, 2014 · 13 comments

Comments

Projects
None yet
@benmccann
Contributor

benmccann commented Jul 31, 2014

@refried originally filed as playframework/playframework#2194. migrating it here

views/foo1.scala.txt (won't compile)

@[L<:shapeless.Nat:shapeless.ops.nat.ToInt](bar: Bar[L])

@bar has size @shapeless.Nat.toInt[L]

views/foo2.scala.txt (will compile, but silly!)

@(bar: Bar[_<:shapeless.Nat], size: Int)

@bar has size @size

controllers/Application.scala

package controllers

import play.api._
import play.api.mvc._
import shapeless.Nat
import shapeless.ops.nat.ToInt

class Bar[L<:Nat]

object Application extends Controller {

  def index = Action {
    Ok(views.html.index("Your new application is ready."))
  }

  // won't compile
  def foo1 = views.txt.foo1(new Bar[Nat._3])

  // needlessly complicated
  def foo2 = {
    def barSize[L<:Nat:ToInt](bar: Bar[L]): Int = Nat.toInt[L]
    val bar = new Bar[Nat._3]
    val size = barSize(bar)
    views.txt.foo2(bar, size)
  }
}
@jaliss

This comment has been minimized.

Show comment
Hide comment
@jaliss

jaliss commented Jan 24, 2015

+1

@mhzajac

This comment has been minimized.

Show comment
Hide comment
@mhzajac

mhzajac Mar 14, 2015

+1, indeed.

mhzajac commented Mar 14, 2015

+1, indeed.

@ScalaWilliamTG

This comment has been minimized.

Show comment
Hide comment
@ScalaWilliamTG

ScalaWilliamTG commented Mar 27, 2015

+1

@dante4d

This comment has been minimized.

Show comment
Hide comment
@dante4d

dante4d commented Mar 28, 2015

+1

@1tchy

This comment has been minimized.

Show comment
Hide comment
@1tchy

1tchy commented Apr 13, 2015

+1

@motns

This comment has been minimized.

Show comment
Hide comment
@motns

motns commented Jun 11, 2015

+1

@joepjoosten

This comment has been minimized.

Show comment
Hide comment
@joepjoosten

joepjoosten commented Apr 6, 2016

+1

@julienrf

This comment has been minimized.

Show comment
Hide comment
@julienrf

julienrf Apr 6, 2016

Contributor

Hi, FWIW, a workaround is to use the string interpolator:

import play.twirl.api.StringInterpolation

def foo[L <: Nat : ToInt](bar: Bar[L]): Html =
  html"$bar has size ${Nat.toInt[L]}"
Contributor

julienrf commented Apr 6, 2016

Hi, FWIW, a workaround is to use the string interpolator:

import play.twirl.api.StringInterpolation

def foo[L <: Nat : ToInt](bar: Bar[L]): Html =
  html"$bar has size ${Nat.toInt[L]}"
@aryairani

This comment has been minimized.

Show comment
Hide comment
@aryairani

aryairani Apr 7, 2016

Aha, thanks @julienrf, that’s good to know.

aryairani commented Apr 7, 2016

Aha, thanks @julienrf, that’s good to know.

@intracer

This comment has been minimized.

Show comment
Hide comment
@intracer

intracer commented Aug 3, 2016

big +1

@Hydromedia

This comment has been minimized.

Show comment
Hide comment
@Hydromedia

Hydromedia commented Oct 19, 2016

+1

@aryairani

This comment has been minimized.

Show comment
Hide comment
@aryairani

aryairani commented Aug 2, 2017

+1

@aryairani

This comment has been minimized.

Show comment
Hide comment
@aryairani

aryairani Aug 2, 2017

I'd like to replace DomainId with a type argument; otherwise I'm going to have to duplicate this code all over the place.

@(domains: List[(DomainId, String)])(implicit QPE: QueryParamEncoder[Option[DomainId]])

<select name="domain">
    <option value="@{QPE.encode(None).value}">--- ALL DOMAINS ---</option>
    @for(pair <- domains) {
        <option value="@{QPE.encode(Some(pair._1)).value}">@pair._2</option>
    }
</select>

aryairani commented Aug 2, 2017

I'd like to replace DomainId with a type argument; otherwise I'm going to have to duplicate this code all over the place.

@(domains: List[(DomainId, String)])(implicit QPE: QueryParamEncoder[Option[DomainId]])

<select name="domain">
    <option value="@{QPE.encode(None).value}">--- ALL DOMAINS ---</option>
    @for(pair <- domains) {
        <option value="@{QPE.encode(Some(pair._1)).value}">@pair._2</option>
    }
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment