Fantastically! I was dreaming about this for a long time. Imagine you have a trait, like
trait Dated {
def createDate: Date
def createAuthor: Author
}
Just some trait form db orm entity. What if you want just set nececery fields to this Dated instance, without any knowledge what case class is it, like:
def setEntityDate(entity: Dated) = entity.copy(createDate = /*now*/, createAuthor = /*currentUser*/)
This task can be accomplished by scala macroses, read about it here
http://stackoverflow.com/questions/10373318/mixing-in-a-trait-dynamically
and here
https://gist.github.com/2559714
No comments:
Post a Comment