Is your feature request related to a problem? Please describe.
No. There is no problem. This pattern can (for the most part) be accomplished today, albeit manually and/or inefficiently.
Describe the solution you'd like
Add an Array.Mutability of Array.Mutability.CopyOnWrite that -- like Array.Mutability.Persistent -- would copy the Array when a change occurs. However, instead of that newly-created Array also being Array.Mutability.Persistent, it would instead be Array.Mutability.Mutable. Think of it as a "one time Persistent" use case, i.e. protecting the original Array from being modified, without every single subsequent "mutation" creating a copy of the most recent version of the Array.
Describe alternatives you've considered
None. We've long wanted a Copy-On-Write optimization, but until now we didn't see an easy way to represent it. Working on a bug (in Java) that was caused by a non-persistent data structure (Java arrays), we realized how easy this capability would now be to add to Ecstasy.
Additional context
The Array API already supports persistent-style operations. The combination of "protect an existing array" with "automatically copy when needed" with "all subsequent changes will not copy" would be quite convenient.
Is your feature request related to a problem? Please describe.
No. There is no problem. This pattern can (for the most part) be accomplished today, albeit manually and/or inefficiently.
Describe the solution you'd like
Add an Array.Mutability of Array.Mutability.CopyOnWrite that -- like Array.Mutability.Persistent -- would copy the Array when a change occurs. However, instead of that newly-created Array also being Array.Mutability.Persistent, it would instead be Array.Mutability.Mutable. Think of it as a "one time Persistent" use case, i.e. protecting the original Array from being modified, without every single subsequent "mutation" creating a copy of the most recent version of the Array.
Describe alternatives you've considered
None. We've long wanted a Copy-On-Write optimization, but until now we didn't see an easy way to represent it. Working on a bug (in Java) that was caused by a non-persistent data structure (Java arrays), we realized how easy this capability would now be to add to Ecstasy.
Additional context
The Array API already supports persistent-style operations. The combination of "protect an existing array" with "automatically copy when needed" with "all subsequent changes will not copy" would be quite convenient.