Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions library/src-scala3/scala/quoted/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package scala

package object quoted {

implicit class LiftExprOps[T](val x: T) extends AnyVal {
def toExpr(implicit ev: Liftable[T]): Expr[T] = ev.toExpr(x)
}

implicit class ListOfExprOps[T](val list: List[Expr[T]]) extends AnyVal {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you have this conversion for free if you make Liftable[List[T]] implicitly available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, Liftable[List[T]] transforms List[T] into Expr[List[T]]. But here we transform List[Expr[T]] into Expr[List[T]].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a generalisation of your liftListOfAny.

def toExprOfList(implicit ev: Type[T]): Expr[List[T]] = {
def rec(list: List[Expr[T]]): Expr[List[T]] = list match {
case x :: xs => '{ (~x) :: (~rec(xs)) }
case Nil => '(Nil)
}
rec(list)
}
}
}
9 changes: 0 additions & 9 deletions library/src/scala/quoted/package.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ object XmlQuote {
// [a0, ...]: Any*
val args2: Expr[List[Any]] = args.unseal.underlyingArgument match {
case Typed(Repeated(args0), _) => // statically known args, make list directly
def liftListOfAny(lst: List[Expr[Any]]): Expr[List[Any]] = lst match {
case x :: xs => '{ ~x :: ~liftListOfAny(xs) }
case Nil => '(Nil)
}
liftListOfAny(args0.map(_.seal[Any]))
args0.map(_.seal[Any]).toExprOfList
case _ =>
'((~args).toList)

Expand Down