Types & data

Updating without mutating

You never change a value in place — you derive a new one with with. Point it at the position to replace; its refers to the value you started from:

c2 is a fresh counter with n bumped to 1 — and c still reads 0, untouched. That’s the whole point: with hands back a copy.

One update is braceless. Several go in braces:

Two more notes: the update uses = (you’re assigning into a copy), not the : of construction — and a path can reach deeper, like doc with line.to = 9.