You seem to be doing it all wrong. It would be an approach to a dynamic language like perl or ruby, but scala is not like it. You might be able to imitate something like scala, but it will be tricky enough for you not to.
.getDetail is not what you often see in scala. If you want to get the name of a person, you are usually just person.name not, person.getDetail(PersonDetail.Name) . What for? Why not? There is simply no reason to do the last when you can do the first.
Similarly for setter: person.copy (firstName = "foo") works better than person.withModiciation(PersonDetail.Name, "foo")
The third case is perhaps the most difficult. What if you want to apply a whole bunch of modifications? Well, I’m still arguing, something like
val list = List( PersonDetail.FirstName -> "foo", PersonDetail.LastName -> "bar", PersonDetail.OtherStuff -> "baz" ) person.withModifications(list)
no better than regular scala
person.copy(firstName = "foo", lastName = "bar", otherStuff = "baz")
source share