Skip to content

Commit 5e3ea88

Browse files
committed
Add quoted.Liftable[List[T]] to the stdlib
1 parent 1faa30f commit 5e3ea88

File tree

6 files changed

+8
-35
lines changed

6 files changed

+8
-35
lines changed

library/src/scala/quoted/Liftable.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ object Liftable {
4343
}
4444
}
4545

46+
given [T: Type: Liftable] as Liftable[List[T]] = new Liftable[List[T]] {
47+
def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match {
48+
case x :: xs => '{ (${this.toExpr(xs)}).::[T](${the[Liftable[T]].toExpr(x)}) }
49+
case Nil => '{ Nil: List[T] }
50+
}
51+
}
52+
4653
}

tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,4 @@ object TypeToolbox {
110110
companionClassOpt.map(_.fullName).getOrElse("").toExpr
111111
}
112112

113-
// TODO add to the std lib
114-
private implicit def listIsLiftable[T: Type: Liftable]: Liftable[List[T]] = new Liftable {
115-
def toExpr(list: List[T]) = list match {
116-
case x :: xs => '{${x.toExpr} :: ${toExpr(xs)}}
117-
case Nil => '{Nil}
118-
}
119-
}
120113
}

tests/run-macros/quote-force/quoted_1.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,4 @@ object Location {
1212
'{new Location(${list})}
1313
}
1414

15-
private implicit def ListIsLiftable[T : Liftable : Type]: Liftable[List[T]] = new Liftable[List[T]] {
16-
def toExpr(x: List[T]) = x match {
17-
case x :: xs => '{ ${x} :: ${xs} }
18-
case Nil => '{ List.empty[T] }
19-
}
20-
}
2115
}

tests/run-macros/tasty-interpolation-1/Macro.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,7 @@ abstract class MacroStringInterpolator[T] {
7777
}
7878

7979
protected implicit def StringContextIsLiftable: Liftable[StringContext] = new Liftable[StringContext] {
80-
def toExpr(strCtx: StringContext) = {
81-
// TODO define in stdlib?
82-
implicit def ListIsLiftable: Liftable[List[String]] = new Liftable[List[String]] {
83-
override def toExpr(list: List[String]) = list match {
84-
case x :: xs => '{${x.toExpr} :: ${toExpr(xs)}}
85-
case Nil => '{Nil}
86-
}
87-
}
88-
'{StringContext(${strCtx.parts.toList}: _*)}
89-
}
80+
def toExpr(strCtx: StringContext) = '{StringContext(${strCtx.parts.toList}: _*)}
9081
}
9182

9283
protected class NotStaticlyKnownError(msg: String, expr: Expr[Any]) extends Exception(msg)

tests/run-macros/tasty-location/quoted_1.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,4 @@ object Location {
1818
'{new Location(${list})}
1919
}
2020

21-
private implicit def ListIsLiftable[T : Liftable : Type]: Liftable[List[T]] = new Liftable[List[T]] {
22-
def toExpr(x: List[T]) = x match {
23-
case x :: xs => '{ $x :: $xs }
24-
case Nil => '{ List.empty[T] }
25-
}
26-
}
2721
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ package liftable {
101101

102102

103103
object Lists {
104-
implicit def ListIsLiftable[T: Liftable](implicit t: Type[T]): Liftable[List[T]] = new Liftable[List[T]] {
105-
def toExpr(x: List[T]): given QuoteContext => Expr[List[T]] = x match {
106-
case x :: xs => '{ (${xs}).::[$t](${x}) }
107-
case Nil => '{ Nil: List[$t] }
108-
}
109-
}
110104

111105
implicit class LiftedOps[T: Liftable](list: Expr[List[T]])(implicit t: Type[T]) {
112106
def foldLeft[U](acc: Expr[U])(f: Expr[(U, T) => U])(implicit u: Type[U], qctx: QuoteContext): Expr[U] =

0 commit comments

Comments
 (0)