We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents fc8b512 + 3c19470 commit f21504aCopy full SHA for f21504a
library/src-bootstrapped/scala/quoted/util/Var.scala
tests/run-staging/staged-streams_1.scala
@@ -680,3 +680,22 @@ object Test {
680
println(run(test10()))
681
}
682
683
+
684
+sealed trait Var[T] {
685
+ def get(using qctx: QuoteContext): Expr[T]
686
+ def update(e: Expr[T])(using qctx: QuoteContext): Expr[Unit]
687
+}
688
689
+object Var {
690
+ def apply[T: Type, U: Type](init: Expr[T])(body: Var[T] => Expr[U])(using qctx: QuoteContext): Expr[U] = '{
691
+ var x = $init
692
+ ${
693
+ body(
694
+ new Var[T] {
695
+ def get(using qctx: QuoteContext): Expr[T] = 'x
696
+ def update(e: Expr[T])(using qctx: QuoteContext): Expr[Unit] = '{ x = $e }
697
+ }
698
+ )
699
700
701
0 commit comments