When compiler version 0.10.6 is released, it will include a syntax for nested record updates.
Before this change, if we have a nested record structure such as:
.level1.val we’d have to write something like this:
This is fairly annoying to write: we need to mention both
level1 twice. With even more nesting it just gets worse:
With the new syntax, the following equivalent expressions are supported:
To update all the
val fields it’d look like this:
In the previous example we updated an object computed by the expression
r - which is just a variable. However if we compute a record by some more complicated expression and then try to update, we wouldn’t just blindly substitute the expression in:
Instead we would first compute
f r and refer to the result twice:
When the compiler desugars nested record updates, to prevent reevaluating the object expression, it introduces a
let binding like the previous example.