Skip to content

Instantly share code, notes, and snippets.

@LeifW
Created February 11, 2013 22:05
Show Gist options
  • Select an option

  • Save LeifW/4758039 to your computer and use it in GitHub Desktop.

Select an option

Save LeifW/4758039 to your computer and use it in GitHub Desktop.
homogeneous tuples
def makeInstances(size: Int) = 1 to size map (n=>
s"""
implicit def V${n}Functor: Functor[V$n] = new Functor[V$n] {
def map[A, B](r: V$n[A])(f: A => B) = V$n(${1 to n map ("f(r.a"+_+")") mkString ", "})
}
""") mkString
def makeClasses(size: Int) = 1 to size map (n=>
s"""
case class V$n[A](${1 to n map ("a"+_+": A") mkString ", "}) {
def toTuple = V$n.unapply(this).get
}
""") mkString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment