4 ms·
> if you just destructively modify and return a copy of the source Then the caller can no longer reference the source without observing the fact you've mutated
by dons 16y ago
> if you just destructively modify and return a copy of the source
Then the caller can no longer reference the source without observing the fact you've mutated it -- you'd have to guarantee they've dropped all references to the now-mutated buffer.
How do you ensure the mutation doesn't leak out like this, breaking all the nice properties?
- ricree 16y agoI think that he means the copy that gets returned is what gets destructively modified. In other words, the overall process winds up being functional and nondestructive, but the intermediate internal steps aren't necessarily so.
- dons 16y agoRight. You better copy the original data structure. That's one good way to guarantee internal mutation (of the copy) isn't going to be visible. Or it gets tricky (e.g. linear types)