Expr

scala.quoted.Expr
See theExpr companion class
object Expr

Constructors for expressions.

Attributes

Companion
class
Source
Expr.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Expr.type

Members list

Value members

Concrete methods

def apply[T](x: T)(using ToExpr[T])(using Quotes): Expr[T]

Creates an expression that will construct the value x.

Creates an expression that will construct the value x.

Type parameters

T

the type of the value to be lifted into an expression

Value parameters

x

the value to lift into a quoted expression

Attributes

Source
Expr.scala
def betaReduce[T](expr: Expr[T])(using Quotes): Expr[T]

e.betaReduce returns an expression that is functionally equivalent to e, however if e is of the form ((y1, ..., yn) => e2)(e1, ..., en) then it optimizes the top most call by returning the result of beta-reducing the application. Similarly, all outermost curried function applications will be beta-reduced, if possible. Otherwise returns expr.

e.betaReduce returns an expression that is functionally equivalent to e, however if e is of the form ((y1, ..., yn) => e2)(e1, ..., en) then it optimizes the top most call by returning the result of beta-reducing the application. Similarly, all outermost curried function applications will be beta-reduced, if possible. Otherwise returns expr.

To retain semantics the argument ei is bound as val yi = ei and by-name arguments to def yi = ei. Some bindings may be elided as an early optimization.

Example:

((a: Int, b: Int) => a + b).apply(x, y)

will be reduced to

val a = x
val b = y
a + b

Generally:

([X1, Y1, ...] => (x1, y1, ...) => ... => [Xn, Yn, ...] => (xn, yn, ...) => f[X1, Y1, ..., Xn, Yn, ...](x1, y1, ..., xn, yn, ...))).apply[Tx1, Ty1, ...](myX1, myY1, ...)....apply[Txn, Tyn, ...](myXn, myYn, ...)

will be reduced to

type X1 = Tx1
type Y1 = Ty1
...
val x1 = myX1
val y1 = myY1
...
type Xn = Txn
type Yn = Tyn
...
val xn = myXn
val yn = myYn
...
f[X1, Y1, ..., Xn, Yn, ...](x1, y1, ..., xn, yn, ...)

Type parameters

T

the type of the expression to beta-reduce

Value parameters

expr

the expression to beta-reduce

Attributes

Returns

the beta-reduced expression, or expr unchanged if no reduction is possible

Source
Expr.scala
def block[T](statements: List[Expr[Any]], expr: Expr[T])(using Quotes): Expr[T]

Returns an expression containing a block with the given statements and ending with the expression Given list of statements s1 :: s2 :: ... :: Nil and an expression e the resulting expression will be equivalent to '{ $s1; $s2; ...; $e }.

Returns an expression containing a block with the given statements and ending with the expression Given list of statements s1 :: s2 :: ... :: Nil and an expression e the resulting expression will be equivalent to '{ $s1; $s2; ...; $e }.

Type parameters

T

the type of the final expression, which determines the block's result type

Value parameters

expr

the final expression whose value becomes the result of the block

statements

the statements to execute before the final expression in the block

Attributes

Source
Expr.scala
def ofList[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[List[T]]

Creates an expression that will construct a copy of this list

Creates an expression that will construct a copy of this list

Transforms a list of expression List(e1, e2, ...) where ei: Expr[T] to an expression equivalent to '{ List($e1, $e2, ...) } typed as an Expr[List[T]]

Type parameters

T

the element type of the list

Value parameters

xs

the sequence of expressions to combine into a list expression

Attributes

Returns

an expression representing a List[T] constructed from the given element expressions

Source
Expr.scala
def ofSeq[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[Seq[T]]

Creates an expression that will construct a copy of this sequence

Creates an expression that will construct a copy of this sequence

Transforms a sequence of expression Seq(e1, e2, ...) where ei: Expr[T] to an expression equivalent to '{ Seq($e1, $e2, ...) } typed as an Expr[Seq[T]]

Type parameters

T

the element type of the sequence

Value parameters

xs

the sequence of expressions to combine

Attributes

Returns

an expression representing a Seq[T] constructed from the given element expressions

Source
Expr.scala
def ofTuple[T <: Tuple](tup: T)(using evidence$1: IsMappedBy[Expr][T], evidence$2: Type[T], Quotes): Expr[InverseMap[T, Expr]]

Given a tuple of the form (Expr[A1], ..., Expr[An]), outputs a tuple Expr[(A1, ..., An)].

Given a tuple of the form (Expr[A1], ..., Expr[An]), outputs a tuple Expr[(A1, ..., An)].

Type parameters

T

the tuple type where each element is wrapped in Expr, e.g., (Expr[A1], ..., Expr[An])

Attributes

Source
Expr.scala
def ofTupleFromSeq(seq: Seq[Expr[Any]])(using Quotes): Expr[Tuple]

Creates an expression that will construct a copy of this tuple

Creates an expression that will construct a copy of this tuple

Transforms a sequence of expression Seq(e1, e2, ...) where ei: Expr[Any] to an expression equivalent to '{ ($e1, $e2, ...) } typed as an Expr[Tuple]

Value parameters

seq

the sequence of element expressions to combine into a tuple expression

Attributes

Returns

an expression representing a tuple constructed from the given element expressions

Source
Expr.scala
def summon[T](using Type[T])(using Quotes): Option[Expr[T]]

Finds a given instance of type T in the current scope. Returns Some containing the expression of the implicit or None if implicit resolution failed.

Finds a given instance of type T in the current scope. Returns Some containing the expression of the implicit or None if implicit resolution failed.

Type parameters

T

type of the implicit parameter

Attributes

Source
Expr.scala
def summonIgnoring[T](using Type[T])(using quotes: Quotes)(ignored: quotes.reflect.Symbol*): Option[Expr[T]]

Finds a given instance of type T in the current scope, while excluding certain symbols from the initial implicit search. Returns Some containing the expression of the implicit or None if implicit resolution failed.

Finds a given instance of type T in the current scope, while excluding certain symbols from the initial implicit search. Returns Some containing the expression of the implicit or None if implicit resolution failed.

Type parameters

T

type of the implicit parameter

Value parameters

ignored

Symbols ignored during the initial implicit search

Attributes

Returns

Some containing the found implicit expression, or None if implicit resolution failed

Note

if the found given requires additional search for other given instances, this additional search will NOT exclude the symbols from the ignored list.

Source
Expr.scala
def unapply[T](x: Expr[T])(using FromExpr[T])(using Quotes): Option[T]

Gets Some of a copy of the value if the expression contains a literal constant or constructor of T. Otherwise returns None.

Gets Some of a copy of the value if the expression contains a literal constant or constructor of T. Otherwise returns None.

Usage:

case '{ ... ${expr @ Expr(value)}: T ...} =>
  // expr: Expr[T]
  // value: T

To directly get the value of an expression expr: Expr[T] consider using expr.value/expr.valueOrError instead.

Type parameters

T

the type of the value to extract from the expression

Value parameters

x

the expression to extract a value from

Attributes

Returns

Some containing the extracted value if x is a literal constant or known constructor, None otherwise

Source
Expr.scala