|
Scala example source code file (Evals.scala)
The Evals.scala Scala example source codepackage scala.reflect.macros package contexts import scala.reflect.runtime.{universe => ru} import scala.tools.reflect.ToolBox trait Evals { self: Context => private lazy val evalMirror = ru.runtimeMirror(universe.analyzer.defaultMacroClassloader) private lazy val evalToolBox = evalMirror.mkToolBox() private lazy val evalImporter = ru.internal.createImporter(universe).asInstanceOf[ru.Importer { val from: universe.type }] def eval[T](expr: Expr[T]): T = { expr.tree match { case global.Literal(global.Constant(value)) => value.asInstanceOf[T] case _ => val imported = evalImporter.importTree(expr.tree) evalToolBox.eval(imported).asInstanceOf[T] } } } Other Scala source code examplesHere is a short list of links related to this Scala Evals.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.