Skip to content

Add Expr.ofFunction1 #14138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 10 additions & 0 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 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]`
Copy link
Contributor

Choose a reason for hiding this comment

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

As you're adding a new method to stdlib's API you should mark it as@experimental

*/
def ofFunction1[A, R](f: Expr[A] => Expr[R])(using Type[R], Type[A])(using Quotes): Expr[A => R] =
Copy link
Contributor

Choose a reason for hiding this comment

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

If we add this we should add it for all function arities. It seems that we would need TupledFunction (see #10416) to be able to write this interface for all function sizes.

'{ (a: A) => ${f('a)} }

/** Creates an expression that will construct a copy of this sequence
*
* Transforms a sequence of expression
Expand Down