From 774c9efd18a8e4779e5bb5b0863b1973239f742a Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Sun, 19 Dec 2021 02:10:23 -0800 Subject: [PATCH 1/2] Add Expr.ofFunction1 --- library/src/scala/quoted/Expr.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala index 65de13f0d3ec..fb65e59ebdfc 100644 --- a/library/src/scala/quoted/Expr.scala +++ b/library/src/scala/quoted/Expr.scala @@ -52,6 +52,16 @@ object Expr { def unapply[T](x: Expr[T])(using FromExpr[T])(using Quotes): Option[T] = scala.Predef.summon[FromExpr[T]].unapply(x) + /** Creates an expression that will construct a function with one parameter + * + * Transforms a sequence of expression + * `a => r` where `a: Expr[A]` and `r: Expr[R]` + * to an expression equivalent to + * `'{ $a => $r }` typed as an `Expr[A => R]` + */ + def ofFunction1[A, R](f: Expr[A] => Expr[R])(using Type[R], Type[A])(using Quotes): Expr[A => R] = + '{ (a: A) => ${f('a)} } + /** Creates an expression that will construct a copy of this sequence * * Transforms a sequence of expression From b3faffc371c9dddf51b4d20389a3fb8106bf4178 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Sun, 19 Dec 2021 19:47:12 -0800 Subject: [PATCH 2/2] Update library/src/scala/quoted/Expr.scala Co-authored-by: Dale Wijnand --- library/src/scala/quoted/Expr.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala index fb65e59ebdfc..520604818804 100644 --- a/library/src/scala/quoted/Expr.scala +++ b/library/src/scala/quoted/Expr.scala @@ -54,7 +54,7 @@ object Expr { /** Creates an expression that will construct a function with one parameter * - * Transforms a sequence of expression + * Transforms the expression * `a => r` where `a: Expr[A]` and `r: Expr[R]` * to an expression equivalent to * `'{ $a => $r }` typed as an `Expr[A => R]`