-
Notifications
You must be signed in to change notification settings - Fork 119
Implement case class default parameters #42
base: development
Are you sure you want to change the base?
Conversation
The patch is very useful, thanks. The only correction is that the default values should be evaluated on each invokation, not just once as in the current implementation. The difference is visible if default arguments have side effects: case class C(id: Int, createdOn: Date = new Date) Each time you invoke val defaultParam = defaultMethod.map(m => () => m.invoke(companionObject)) and invoke it when creating the object: if (field != null || value != null) {
values += value
} else {
// see if a default value was supplied
paramDefault.foreach ( values += _() )
} |
@ ksvladimir Good catch! |
I've been really wanting this feature too. Any chance it could get merged into codahale:development ? |
Thanks to @opyate and @ksvladimir for the update to the original patch. I have implemented it in my fork. |
+1 please pull this. |
It seems there has been a lot of pull requests recently that are basically just sitting in limbo. Is this project no longer actively maintained? |
+1 |
+1 very useful addition, would love to see this merged. |
(as discussed via email)
You have your domain stuff as case classes with default parameters,
e.g. case class Message(msg: String, priority: String = "low")
So, Message(msg="hey") will have a default low priority.
Now you can send something like this on the messaging infrastructure:
{
"msg" : "Hello, World!"
}
...and the serializer in your message converter won't complain about
the lack of priority flag, and will serialize a Message with "low"
priority.