Last active
November 14, 2017 04:16
-
-
Save sujeet100/74346963bb1281619a08f9960a46e24c to your computer and use it in GitHub Desktop.
Quill: Tail recursive liftQuery macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait TupleQuery { | |
this: io.getquill.context.Context[_, _] => | |
def liftTuples[T1: Encoder, T2: Encoder](l: List[(T1, T2)]): Quoted[Query[(T1, T2)]] = | |
liftTuples(l, (t: (T1, T2)) => infix"(${lift(t._1)}, ${lift(t._2)})", null) | |
private def liftTuples[T, U](l: List[T], f: T => Quoted[Any], acc: Quoted[Query[U]]): Quoted[Query[U]] = { | |
l match { | |
case Nil => infix"".as[Query[U]] | |
case head :: Nil => infix"${f(head)}, $acc".as[Query[U]] | |
case head :: tail if acc == null => liftTuples(tail, f, infix"${f(head)}".as[Query[U]]) | |
case head :: tail => liftTuples(tail, f, infix"${f(head)}, $acc".as[Query[U]]) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment