Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modifyAll and setTo #27

Open
justinhj opened this issue Mar 2, 2016 · 4 comments
Open

modifyAll and setTo #27

justinhj opened this issue Mar 2, 2016 · 4 comments

Comments

@justinhj
Copy link

justinhj commented Mar 2, 2016

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

@adamw
Copy link
Member

adamw commented Mar 3, 2016

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?

@justinhj
Copy link
Author

justinhj commented Mar 3, 2016

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.

@adamw
Copy link
Member

adamw commented Mar 3, 2016

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

@justinhj
Copy link
Author

justinhj commented Mar 3, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants