Skip to content

Commit 5bd91a6

Browse files
committed
Fix a code example in macros.mds
1 parent 222fe0b commit 5bd91a6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

docs/docs/reference/metaprogramming/macros.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,19 +632,19 @@ It is possible to deconstruct or extract values out of `Expr` using pattern matc
632632

633633
`scala.quoted` contains objects that can help extracting values from `Expr`.
634634

635-
* `scala.quoted.Unlifted`: matches an expression of a value (or list of values) and returns the value (or list of values).
636-
* `scala.quoted.Const`/`scala.quoted.Consts`: Same as `Unlifted` but only works on primitive values.
637-
* `scala.quoted.Varargs`: matches an explicit sequence of expressions and returns them. These sequences are useful to get individual `Expr[T]` out of a varargs expression of type `Expr[Seq[T]]`.
638-
635+
- `scala.quoted.Unlifted`: matches an expression of a value (or list of values) and returns the value (or list of values).
636+
- `scala.quoted.Const`/`scala.quoted.Consts`: Same as `Unlifted` but only works on primitive values.
637+
- `scala.quoted.Varargs`: matches an explicit sequence of expressions and returns them. These sequences are useful to get individual `Expr[T]` out of a varargs expression of type `Expr[Seq[T]]`.
639638

640639
These could be used in the following way to optimize any call to `sum` that has statically known values.
640+
641641
```scala
642642
inline def sum(inline args: Int*): Int = ${ sumExpr('args) }
643643
private def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes): Expr[Int] = argsExpr match {
644644
case Varargs(Unlifted(args)) => // args is of type Seq[Int]
645645
Expr(args.sum) // precompute result of sum
646646
case Varargs(argExprs) => // argExprs is of type Seq[Expr[Int]]
647-
val staticSum: Int = argExprs.map(_.unlift.getOrElse(0))
647+
val staticSum: Int = argExprs.map(_.unlift.getOrElse(0)).sum
648648
val dynamicSum: Seq[Expr[Int]] = argExprs.filter(_.unlift.isEmpty)
649649
dynamicSum.foldLeft(Expr(staticSum))((acc, arg) => '{ $acc + $arg })
650650
case _ =>

0 commit comments

Comments
 (0)