class Queryable[T, Repr](query: Query) {
macro def filter(p: T => Boolean): Repr = <[
val b = $this.newBuilder
b.query = Filter($this.query, $reify(p))
b.result
]>
}
val products = db.products
products.filter(p => p.startsWith("foo")).toList
--
My takeaways :
1. adding LINQ support to Scala via macros
2. macros virtualize XXX, where XXX = vals, vars, defs, types, classes, traits. So macro XXX can be used in place of XXX.
The author also says "We can tailor macros to fit your particular use case". He mentions OR-mapping, and a Scala-to-javascript compiler that might end up using these macro invocations, among other things.
Pls read slide 10 of this document - http://scalamacros.org/talks/2011-10-18-WhatsUp.pdf
--Proposed Code snippet with macro ---
class Queryable[T, Repr](query: Query) { macro def filter(p: T => Boolean): Repr = <[ val b = $this.newBuilder b.query = Filter($this.query, $reify(p)) b.result ]> } val products = db.products products.filter(p => p.startsWith("foo")).toList --
My takeaways : 1. adding LINQ support to Scala via macros 2. macros virtualize XXX, where XXX = vals, vars, defs, types, classes, traits. So macro XXX can be used in place of XXX.
The author also says "We can tailor macros to fit your particular use case". He mentions OR-mapping, and a Scala-to-javascript compiler that might end up using these macro invocations, among other things.