Skip to content

Commit 5796226

Browse files
committed
Add quoted.Liftable[Map[T, U]] to the stdlib
1 parent 6f02d96 commit 5796226

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

library/src/scala/quoted/Liftable.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ object Liftable {
7171
'{ Set(${set.toSeq.toExpr}: _*) }
7272
}
7373

74+
given [T: Type: Liftable, U: Type: Liftable] as Liftable[Map[T, U]] = new Liftable[Map[T, U]] {
75+
def toExpr(map: Map[T, U]): given QuoteContext => Expr[Map[T, U]] =
76+
'{ Map(${map.toSeq.toExpr}: _*) }
77+
}
78+
7479
given [T: Type: Liftable] as Liftable[Option[T]] = new Liftable[Option[T]] {
7580
def toExpr(x: Option[T]): given QuoteContext => Expr[Option[T]] = x match {
7681
case Some(x) => '{ Some[T](${x.toExpr}) }

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ object Test {
5656
val set: Set[Int] = Set(1, 2, 3)
5757
val liftedSet: Expr[Set[Int]] = set
5858

59+
val map: Map[Int, Char] = Map(1 -> 'a', 2 -> 'b', 3 -> 'c')
60+
val liftedMap: Expr[Map[Int, Char]] = map
61+
5962
liftedList.foldLeft[Int](0)('{ (acc: Int, x: Int) => acc + x }).show
6063
liftedList.foreach('{ (x: Int) => println(x) }).show
6164

0 commit comments

Comments
 (0)