Scala case class generated field value
Posted
by
Petteri Hietavirta
on Stack Overflow
See other posts from Stack Overflow
or by Petteri Hietavirta
Published on 2014-06-13T07:02:37Z
Indexed on
2014/06/13
9:25 UTC
Read the original article
Hit count: 232
I have an existing Scala application and it uses case classes which are then persisted in MongoDB. I need to introduce a new field to a case class but the value of it is derived from existing field.
For example, there is phone number and I want to add normalised phone number while keeping the original phone number. I'll update the existing records in MongoDB but I would need to add this normalisation feature to existing save and update code.
So, is there any nice shortcut in Scala to add a "hook" to a certain field of a case class? For example, in Java one could modify setter of the phone number.
© Stack Overflow or respective owner