cgta.oscala.util.Tuplizer.scala Maven / Gradle / Ivy
The newest version!
package cgta.oscala
package util
//////////////////////////////////////////////////////////////
// Copyright (c) 2014 Ben Jackman, Jeff Gomberg
// All Rights Reserved
// please contact [email protected] or [email protected]
// for licensing inquiries
// Created by bjackman @ 6/29/14 8:47 PM
//////////////////////////////////////////////////////////////
object TuplizerGen {
def main(args: Array[String]) {
println("object Tuplizer {")
for (n <- 1 to 22) {
val ns = 1 to n
val Ts = ns.map(n => s"T$n").mkString(",")
val tt = s"Tuple$n[$Ts]"
val c2t = {
val fs = ns.map(n => s"c.productElement(${n - 1}).asInstanceOf[T$n]").mkString(",")
s"(c : A) => Tuple$n($fs)"
}
val t2c = s"f.tupled"
println(s"def apply[A <: Product, $Ts](f : Function$n[$Ts, A]): Tuplizer[A, $tt] = Tuplizer[A, $tt]($c2t, $t2c)")
}
println("}")
}
}
//Turns case classes into tuples and vice versa
//I was writing this for the SLICK Stuff, but I am going to stop for a bit.
case class Tuplizer[C, T](caseToTuple: C => T, tupleToCase: T => C) {
type CC = C
type TT = T
}
//
//object Tuplizer {
// def apply[A <: Product, T1](f: Function1[T1, A]): Tuplizer[A, Tuple1[T1]] = Tuplizer[A, Tuple1[T1]]((c: A) => Tuple1(c.productElement(0).asInstanceOf[T1]), f.tupled)
// def apply[A <: Product, T1, T2](f: Function2[T1, T2, A]): Tuplizer[A, Tuple2[T1, T2]] = Tuplizer[A, Tuple2[T1, T2]]((c: A) => Tuple2(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2]), f.tupled)
// def apply[A <: Product, T1, T2, T3](f: Function3[T1, T2, T3, A]): Tuplizer[A, Tuple3[T1, T2, T3]] = Tuplizer[A, Tuple3[T1, T2, T3]]((c: A) => Tuple3(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4](f: Function4[T1, T2, T3, T4, A]): Tuplizer[A, Tuple4[T1, T2, T3, T4]] = Tuplizer[A, Tuple4[T1, T2, T3, T4]]((c: A) => Tuple4(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5](f: Function5[T1, T2, T3, T4, T5, A]): Tuplizer[A, Tuple5[T1, T2, T3, T4, T5]] = Tuplizer[A, Tuple5[T1, T2, T3, T4, T5]]((c: A) => Tuple5(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6](f: Function6[T1, T2, T3, T4, T5, T6, A]): Tuplizer[A, Tuple6[T1, T2, T3, T4, T5, T6]] = Tuplizer[A, Tuple6[T1, T2, T3, T4, T5, T6]]((c: A) => Tuple6(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7](f: Function7[T1, T2, T3, T4, T5, T6, T7, A]): Tuplizer[A, Tuple7[T1, T2, T3, T4, T5, T6, T7]] = Tuplizer[A, Tuple7[T1, T2, T3, T4, T5, T6, T7]]((c: A) => Tuple7(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8](f: Function8[T1, T2, T3, T4, T5, T6, T7, T8, A]): Tuplizer[A, Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]] = Tuplizer[A, Tuple8[T1, T2, T3, T4, T5, T6, T7, T8]]((c: A) => Tuple8(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9](f: Function9[T1, T2, T3, T4, T5, T6, T7, T8, T9, A]): Tuplizer[A, Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]] = Tuplizer[A, Tuple9[T1, T2, T3, T4, T5, T6, T7, T8, T9]]((c: A) => Tuple9(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](f: Function10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, A]): Tuplizer[A, Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]] = Tuplizer[A, Tuple10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]((c: A) => Tuple10(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](f: Function11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, A]): Tuplizer[A, Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]] = Tuplizer[A, Tuple11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11]]((c: A) => Tuple11(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](f: Function12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, A]): Tuplizer[A, Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]] = Tuplizer[A, Tuple12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12]]((c: A) => Tuple12(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](f: Function13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, A]): Tuplizer[A, Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]] = Tuplizer[A, Tuple13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13]]((c: A) => Tuple13(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](f: Function14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, A]): Tuplizer[A, Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]] = Tuplizer[A, Tuple14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14]]((c: A) => Tuple14(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13], c.productElement(13).asInstanceOf[T14]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](f: Function15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, A]): Tuplizer[A, Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]] = Tuplizer[A, Tuple15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15]]((c: A) => Tuple15(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13], c.productElement(13).asInstanceOf[T14], c.productElement(14).asInstanceOf[T15]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](f: Function16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, A]): Tuplizer[A, Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]] = Tuplizer[A, Tuple16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16]]((c: A) => Tuple16(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13], c.productElement(13).asInstanceOf[T14], c.productElement(14).asInstanceOf[T15], c.productElement(15).asInstanceOf[T16]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](f: Function17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, A]): Tuplizer[A, Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]] = Tuplizer[A, Tuple17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17]]((c: A) => Tuple17(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13], c.productElement(13).asInstanceOf[T14], c.productElement(14).asInstanceOf[T15], c.productElement(15).asInstanceOf[T16], c.productElement(16).asInstanceOf[T17]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](f: Function18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, A]): Tuplizer[A, Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]] = Tuplizer[A, Tuple18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18]]((c: A) => Tuple18(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13], c.productElement(13).asInstanceOf[T14], c.productElement(14).asInstanceOf[T15], c.productElement(15).asInstanceOf[T16], c.productElement(16).asInstanceOf[T17], c.productElement(17).asInstanceOf[T18]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](f: Function19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, A]): Tuplizer[A, Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]] = Tuplizer[A, Tuple19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19]]((c: A) => Tuple19(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13], c.productElement(13).asInstanceOf[T14], c.productElement(14).asInstanceOf[T15], c.productElement(15).asInstanceOf[T16], c.productElement(16).asInstanceOf[T17], c.productElement(17).asInstanceOf[T18], c.productElement(18).asInstanceOf[T19]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](f: Function20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, A]): Tuplizer[A, Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]] = Tuplizer[A, Tuple20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20]]((c: A) => Tuple20(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13], c.productElement(13).asInstanceOf[T14], c.productElement(14).asInstanceOf[T15], c.productElement(15).asInstanceOf[T16], c.productElement(16).asInstanceOf[T17], c.productElement(17).asInstanceOf[T18], c.productElement(18).asInstanceOf[T19], c.productElement(19).asInstanceOf[T20]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](f: Function21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, A]): Tuplizer[A, Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]] = Tuplizer[A, Tuple21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21]]((c: A) => Tuple21(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13], c.productElement(13).asInstanceOf[T14], c.productElement(14).asInstanceOf[T15], c.productElement(15).asInstanceOf[T16], c.productElement(16).asInstanceOf[T17], c.productElement(17).asInstanceOf[T18], c.productElement(18).asInstanceOf[T19], c.productElement(19).asInstanceOf[T20], c.productElement(20).asInstanceOf[T21]), f.tupled)
// def apply[A <: Product, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](f: Function22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, A]): Tuplizer[A, Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]] = Tuplizer[A, Tuple22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22]]((c: A) => Tuple22(c.productElement(0).asInstanceOf[T1], c.productElement(1).asInstanceOf[T2], c.productElement(2).asInstanceOf[T3], c.productElement(3).asInstanceOf[T4], c.productElement(4).asInstanceOf[T5], c.productElement(5).asInstanceOf[T6], c.productElement(6).asInstanceOf[T7], c.productElement(7).asInstanceOf[T8], c.productElement(8).asInstanceOf[T9], c.productElement(9).asInstanceOf[T10], c.productElement(10).asInstanceOf[T11], c.productElement(11).asInstanceOf[T12], c.productElement(12).asInstanceOf[T13], c.productElement(13).asInstanceOf[T14], c.productElement(14).asInstanceOf[T15], c.productElement(15).asInstanceOf[T16], c.productElement(16).asInstanceOf[T17], c.productElement(17).asInstanceOf[T18], c.productElement(18).asInstanceOf[T19], c.productElement(19).asInstanceOf[T20], c.productElement(20).asInstanceOf[T21], c.productElement(21).asInstanceOf[T22]), f.tupled)
//}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy