Skip to content

Commit b087999

Browse files
committed
Update documentation of Const
1 parent e308ffd commit b087999

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

library/src/scala/quoted/Const.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ package scala.quoted
44
object Const {
55

66
/** Matches expressions containing literal constant values and extracts the value.
7-
* It may match expressions of type Boolean, Byte, Short, Int, Long,
8-
* Float, Double, Char, String, ClassTag, scala.Symbol, Null and Unit.
7+
*
8+
* - Converts expression containg literal values to their values:
9+
* - `'{1}` -> `1`, `'{2}` -> `2`, ...
10+
* - For all primitive types and `String`
911
*
1012
* Usage:
1113
* ```
12-
* (x: Expr[B]) match {
13-
* case Const(value: B) => ...
14-
* }
14+
* case '{ ... ${expr @ Const(value)}: T ...} =>
15+
* // expr: Expr[T]
16+
* // value: T
1517
* ```
18+
*
19+
* To directly unlift an expression `expr: Expr[T]` consider using `expr.unlift`/`expr.unliftOrError` insead.
1620
*/
1721
def unapply[T](expr: Expr[T])(using Quotes): Option[T] = {
1822
import quotes.reflect._

library/src/scala/quoted/Consts.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ object Consts {
1414
* ...
1515
* }
1616
* ```
17+
*
18+
* To directly unlift all expressions in a sequence `exprs: Seq[Expr[T]]` consider using `exprs.map(_.unlift)`/`exprs.map(_.unliftOrError)` insead.
1719
*/
1820
def unapply[T](exprs: Seq[Expr[T]])(using Quotes): Option[Seq[T]] =
1921
exprs.foldRight(Option(List.empty[T])) { (elem, acc) =>

0 commit comments

Comments
 (0)