quicklens icon indicating copy to clipboard operation
quicklens copied to clipboard

modifyAll and setTo

Open justinhj opened this issue 9 years ago • 4 comments

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

justinhj avatar Mar 02 '16 19:03 justinhj

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?

adamw avatar Mar 03 '16 10:03 adamw

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.

justinhj avatar Mar 03 '16 15:03 justinhj

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 ;)

adamw avatar Mar 03 '16 15:03 adamw

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.

justinhj avatar Mar 03 '16 15:03 justinhj