Generated with
Copyright (c) 2002-2026, LAMP/EPFL
Copyright (c) 2002-2026, LAMP/EPFL
scala.quoted.Varargs
Expression representation of literal sequence of expressions.
Varargs can be used to create the an expression args that will be used as varargs '{ f($args: _*) } or it can be used to extract all the arguments of the a varargs.
Attributes
Source
Varargs.scala
Graph
Reset zoom Hide graph Show graph
Supertypes
Self type
Members list
Lifts this sequence of expressions into an expression of a sequence
Lifts this sequence of expressions into an expression of a 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]]
Usage:
def f(using Quotes) = {
import quotes.reflect.*
'{ List(${Varargs(List('{1}, '{2}, '{3}))}: _*) } // equivalent to '{ List(1, 2, 3) }
}
Type parameters
T
the element type of the expressions in the sequence
Value parameters
xs
the sequence of individual expressions to lift into a single expression
Attributes
Returns
an expression representing the sequence Seq(xs(0), xs(1), ...) as an Expr[Seq[T]]
Source
Varargs.scala
Matches a literal sequence of expressions and returns a sequence of expressions.
Matches a literal sequence of expressions and returns a sequence of expressions.
Usage:
inline def sum(args: Int*): Int = ${ sumExpr('args) }
def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes): Expr[Int] = argsExpr match
case Varargs(argVarargs) => Expr(argVarargs.size)
// argVarargs: Seq[Expr[Int]]
Type parameters
T
the element type of the varargs sequence
Value parameters
expr
the expression of a sequence to destructure into individual expressions
Attributes
Returns
Some containing the individual element expressions, or None if the expression is not a literal sequence
Source
Varargs.scala