Skip to content

Commit ddaf5b6

Browse files
committed
Add quoted.Liftable[Seq[T]] to the stdlib
1 parent eb125d5 commit ddaf5b6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

library/src/scala/quoted/Liftable.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ object Liftable {
5252
}
5353
}
5454

55+
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+
}
60+
}
61+
5562
given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] {
5663
def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match {
5764
case x :: xs => '{ (${xs.toExpr}).::[T](${x.toExpr}) }

tests/run-with-compiler/quote-lib.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ object Test {
2929
val list: List[Int] = List(1, 2, 3)
3030
val liftedList: Expr[List[Int]] = list
3131

32+
val seq: Seq[Int] = Seq(1, 2, 3)
33+
val liftedSeq: Expr[Seq[Int]] = seq
34+
3235
liftedList.foldLeft[Int](0)('{ (acc: Int, x: Int) => acc + x }).show
3336
liftedList.foreach('{ (x: Int) => println(x) }).show
3437

0 commit comments

Comments
 (0)