I am looking at a piece of Scala macro which provides an implicit implementation of a class. This class converts a map of field values to a case class. The macro can be found here and this is the explanation behind it.
Currently the implementation…
I would like injecting a method 'toCSV' to parse a class into CSV String. My function take two paramters :
Seq[String] : header
Seq[Seq[Any]] : fields
My macro :
class model extends scala.annotation.StaticAnnotation {
inline def apply(defn:…
this is what i want:
scala> var x:Int = 10
x: Int = 10
scala> var y:Int = 20
y: Int = 20
scala> val ret = q"return $x>$y"
ret: universe.Return = return 10.$greater(20)
scala> val result1 = toolbox.compile(ret)()
result1: Any = false
But the…
I am trying to create an implicit encoder using Circe. However this encoder will be created using an annotation hence I am using Scalameta. Here is my code. However, the compiler complains about having an override statement within quasiquotes.
class…
I was wondering if i could perform a sort of a nested quasi quote evaluation.
Let's say i have a function call
q"${function(args)}"
That returns "add(x,y)" (a string)
How can i make it evaluate this?
Something like
val a =…
Can you please explain why the two usages of Scala quasiquote below give different output between result1 and result2? Is it possible to reproduce result3 using quasiquote? i.e parse a string content and evaluate it?
import…
With Scala's quasiquotes you can build trees of selects easily, like so:
> tq"a.b.MyObj"
res: Select(Select(Ident(TermName("a")), TermName("b")), TermName("MyObj"))
My question is, how do I do this if the list of things to select from…
Trying quasiquotes for the first time to generically produce new case classes:
val universe: scala.reflect.runtime.universe.type = scala.reflect.runtime.universe
import universe._
import scala.reflect.runtime.{currentMirror => m}
import…
I have a macro which I want to use to log the time it takes to execute a block that might return something useful. So if I have something like
val y = f(x) I will change to val y = Timed(f(x)) to get the time it took to execute the function in the…
I need Scala macros (reify, quasiquote, macro impl) for my Scala assertions library.
I want to be able to do this:
object1.assertEquals(object2) // success: object1 = object2
Or like this:
3.assertEquals(1 + 1) // failure: 1 + 1 /= 3
Can Scala…
I took this Scala quasiquote example from the book "Programming Scala" (2nd Edition)
I am getting this error: https://issues.scala-lang.org/browse/SI-9711
The type inference says "Trees#Tree", but the type inference is off.
import…
As an overview, I am trying to dynamically create a constructor for a case class from a Cassandra Java Row using reflection to find the primary constructor for the case class, and then trying to extract the values from the Cassandra Row.…
For some reason every time I try to call a function with an implicit parameter from quasiquotes, it fails with
Can't unquote x.universe.Tree, consider providing an implicit instance of Liftable[x.universe.Tree]
What's wrong with that? Am I not…
I am trying to write this case authorDao: AuthorDao => authorDao so that it returns the subclass of Dao itself.
When I use this quasi quote:
val daoType = TypeName(daoName)
val caseTerm = TermName(daoName.toLowerCase)
cases.append(cq"$caseTerm:…
For example:
q"import scala.collection.mutable.Buffer\ndef foo: Buffer[Int] = ???"
This gives an error, because the newline characters is not resolved.