Skip to content

Instantly share code, notes, and snippets.

@kevinwright
Created January 5, 2014 13:16
Show Gist options
  • Select an option

  • Save kevinwright/8268045 to your computer and use it in GitHub Desktop.

Select an option

Save kevinwright/8268045 to your computer and use it in GitHub Desktop.
string interpolation with "creatively" named values
// intended for boilerplate.scala in shapeless...
val arity = 3
val N = arity
val typeVars = (0 until arity) map (n => (n+'A').toChar)
// = Vector(A, B, C)
val `A..Z` = typeVars.mkString(", ")
// = "A, B, C"
val `A::Z` = typeVars.mkString("", " :: ", " :: HNil")
// = "A :: B :: C :: HNil"
s"implicit def fnFromProduct${N}[${`A..Z`}]: Aux[(${`A::Z`}) => Res, (${`A..Z`}) => Res] = new FnFromProduct[(${`A::Z`}) => Res] {"
// = implicit def fnFromProduct3[A, B, C]: Aux[(A :: B :: C :: HNil) => Res, (A, B, C) => Res] = new FnFromProduct[(A :: B :: C :: HNil) => Res] {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment