Skip to content

Instantly share code, notes, and snippets.

@milessabin milessabin/tupletype.scala
Last active Aug 13, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.