Provide `.copy` for named tuples

I want to choose named tuples over case classes in some scenarios where they feel more natural and involve less boilerplate, but I’ve found that they bizarrely do not ship with a .copy method for easily modifying them like case classes do.

type Foo = (a: Int, b: Int)

val foo: Foo = (a = 1, b = 0)

val modified = foo.copy(a = foo.a+1)
// value copy is not a member of Foo

I don’t see a reason why this method doesn’t exist for named tuples, and the fact that it doesn’t while it does for case classes acts effectively as a deterrent for me in ever choosing named tuples as the abstraction if I care about convenience – which is not the sort of thing that should factor in to my decision making process when choosing the right abstractions.

Can we add a pre-generated copy method for named tuples, so they are as convenient to use as case classes?

1 Like

It will be added soon

1 Like

Am I reading it right that it will be called copyFrom instead of copy, merely because the argument requires an extra pair of parentheses?

Couldn’t the name of the parameter just be from to indicate the semantic difference, instead of putting that in the name? copy(from = (...

This introduces more inconsistency in my callsites that, again, kinda makes me not want to use named tuples

It’s experimental for now, the name will probably be .copy in the final implementation (as intended at the beginning of the Contributors discussion). I think .copyFrom is the internal name in the compiler for now, not the final user facing name.

2 Likes