-
-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Labels
RFCNew specifications of ErgNew specifications of ErgenhancementNew feature or requestNew feature or request
Description
If you want to replace only one element in a record, you can do it like:
rec = { x = 1; y = 2; z = 3 }
assert { x = rec.x; y = rec.y; z = 2 } == { x = 1; y = 2; z = 2 }This is tedious and requires changing the code every time other fields are added or removed.
So, We propose to add a replace method to the record type.
rec = { x = 1; y = 2; z = 3 }
assert rec.replace({ z = 2 }) == { x = 1; y = 2; z = 2 }
assert rec.replace({ x = 2; z = 2 }) == { x = 2; y = 2; z = 2 }The argument is a record containing the fields to be rewritten. If you provide a record containing a field that does not exist in self, a compilation error will occur.
Also, the replace method returns the same type of self. Therefore, all record field types given as an argument must match the field types of the original record.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
RFCNew specifications of ErgNew specifications of ErgenhancementNew feature or requestNew feature or request