quicklens
quicklens copied to clipboard
modifyAll and setTo
Is it possible to use 'modifyAll' and something like 'setTo' to set multiple fields without doing duplicate copy operations? In the example code I only see modifyAll being used with 'using'.
Ideally setTo would take a tuple that matches the order of arguments to modifyAll
Wouldn't a chain:
person
.modify(_.f1).setTo(v1)
.modify(_.f2).setTo(v2)
.modify(_.f3).setTo(v3)
be more readable? With the tuples approach, you have to mentally connect the fields-tuple with the values-tuple, which could be error prone?
Yes you're right it's more readable and safer that way. I was just wondering if it would be more efficient if it was done in one call.
Probably, a bit, but then if modifying a case class once or three times makes a difference, maybe it's not a good idea to use (immutable) case classes anyway ;)
That's true. We're making heavy use of this pattern but I can always refactor it locally if there's a hot point in the code. Thanks for the input.
On Mar 3, 2016, at 7:17 AM, Adam Warski [email protected] wrote:
Probably, a bit, but then if modifying a case class once or three times makes a difference, maybe it's not a good idea to use (immutable) case classes anyway ;)
— Reply to this email directly or view it on GitHub.