FAQ
Expr(...)
or '{...}
?
Which should I use If you can write your code using Expr(...)
, you will evaluate more at compile time.
Only use '{...}
if you really need to evaluate the code later at runtime, usually because it depends on runtime values.
Expr(true)
or '{true}
?
Which is better between All quotes containing a value of a primitive type is optimised to an Expr.apply
.
Choose one in your project and stick with a single notation to avoid confusion.
Expr
?
How do I get a value out of an If the expression represents a value, you can use .unlift
, .unliftOrError
, Unlifted.unapply
or Const.unapply
.
Expr
?
How can I get the precise type of an We can get the precise type (Type
) of an Expr
using the following pattern match:
val x: Expr[X] = ...
x match
case '{ $x: $t } =>
// `x: Expr[X & t.T]` where `t` is the precise type of `x`