Skip to content

Commit 81dd055

Browse files
committed
Use reuse toExprOfSeq and toExprOfList
1 parent 5796226 commit 81dd055

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

library/src-non-bootstrapped/scala/quoted/package.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@ package object quoted {
1010

1111
implicit object ExprOps {
1212
def (x: T) toExpr[T: Liftable] given QuoteContext: Expr[T] = the[Liftable[T]].toExpr(x)
13+
14+
def (seq: Seq[Expr[T]]) toExprOfSeq[T] given (tp: Type[T], qctx: QuoteContext): Expr[Seq[T]] =
15+
throw new Exception("Non bootsrapped library")
16+
17+
def (list: List[Expr[T]]) toExprOfList[T] given Type[T], QuoteContext: Expr[List[T]] =
18+
throw new Exception("Non bootsrapped library")
1319
}
1420
}

library/src/scala/quoted/Liftable.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,13 @@ object Liftable {
5353
}
5454

5555
given [T: Type: Liftable] as Liftable[Seq[T]] = new Liftable[Seq[T]] {
56-
def toExpr(seq: Seq[T]): given QuoteContext => Expr[Seq[T]] = given qctx => {
57-
import qctx.tasty._
58-
Repeated(seq.map(x => the[Liftable[T]].toExpr(x).unseal).toList, the[quoted.Type[T]].unseal).seal.asInstanceOf[Expr[Seq[T]]]
59-
}
56+
def toExpr(xs: Seq[T]): given QuoteContext => Expr[Seq[T]] =
57+
xs.map(the[Liftable[T]].toExpr).toExprOfSeq
6058
}
6159

6260
given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] {
63-
def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match {
64-
case x :: xs => '{ (${xs.toExpr}).::[T](${x.toExpr}) }
65-
case Nil => '{ Nil: List[T] }
66-
}
61+
def toExpr(xs: List[T]): given QuoteContext => Expr[List[T]] =
62+
xs.map(the[Liftable[T]].toExpr).toExprOfList
6763
}
6864

6965
given [T: Type: Liftable] as Liftable[Set[T]] = new Liftable[Set[T]] {

0 commit comments

Comments
 (0)