Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Statically typed reflection for Scala
Failed to load latest commit information.
src Better error handling and some code cleanup
.gitignore For great justice
LICENSE.txt Added license
README.markdown Added readme
build.sbt Removed unneeded dependencies
version.sbt For great justice


Statically typed reflection for Scala

A problem with many query DSLs in Scala is that they rely on referring to properties of objects using Strings. This means there are no compile time checks that the query is correct, and small typos can lead to very frustrating and hard to find bugs.

ScalaFlect solves this by allowing statically typed reflection on classes. It is designed primarily be used as a building block for building DSLs for querying data stores/representations that get mapped to Scala classes, for example, a database object mapper.

An example of what a DSL built on ScalaFlect might look like can be seen here:

* Blog post DAO
class BlogPostDao extends ObjectListDao(classOf[BlogPost]) {

  def findByAuthor(author: String) = {
      $( %= author

  def findPublishedByTag(tag: String) = {
      $(_.tags.$) %= tag,
      $(_.published) %= true

  def findPostsCommentedOnByAuthor(author: String) = {
      $(_.comments.$.author) %= author

case class BlogPost(author: String, title: String, published: Boolean, tags: Set[String], comments: List[Comment])
case class Comment(author: String, text: String)

For an example of this code in action, see

Under the hood

ScalaFlect uses byte code analysis to work out which properties are accessed in the passed in reflection function. It caches the results so that subsequent uses of that function are very fast.

Something went wrong with that request. Please try again.