Proposal: record setters

So the main complaint about nested record update falls kind of flat when you take a step back and consider the architectural decisions that led you needing to do a nested record update.

If settings is “important” enough (read; a stand-alone domain we can model) to be a record itself then we shouldn’t be updating it in the model’s update function.

{ model.settings | darkMode = True }

We can’t do this but we can just as well do:

{ model | settings = Settings.toggleDarkMode model.settings }

Which moves the responsibility into a module that is concerned about the correct data type.

6 Likes