Skip to content

Instantly share code, notes, and snippets.

@milessabin
Last active August 13, 2019 16:51
Show Gist options
  • Save milessabin/a684a84b6aa2e85b9508d7a672b7cb71 to your computer and use it in GitHub Desktop.
Save milessabin/a684a84b6aa2e85b9508d7a672b7cb71 to your computer and use it in GitHub Desktop.
def tupleType(tpes: List[Type]): Type = {
val PairType = typeOf[_ *: _] match {
case Type.IsAppliedType(tp) => tp.tycon
}
@tailrec
def nestedPairs(tpes: List[Type], acc: Type): Type = tpes match {
case Nil => acc
case hd :: tail => nestedPairs(tail, Type.AppliedType(PairType, List(hd, acc)))
}
tpes.length match {
case 0 => defn.UnitType
case n if n <= 22 => Type.AppliedType(defn.TupleClass(n).asClassDef /* what goes here? */, tpes)
case n => nestedPairs(tpes.reverse, defn.UnitType)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment