[swift-evolution] [Pitch] Removing the empty initialiser requirement from RangeReplaceableCollection

Haravikk swift-evolution at haravikk.me
Thu Jul 7 14:03:59 CDT 2016


> On 7 Jul 2016, at 15:57, Karl via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I believe the idea of RRC is that all you need to implement is the empty initialiser and replaceSubrange(), and everything else (e.g. Append, insert) is implemented in terms of those. Even the initialiser which takes existing collection just initialises and empty one and appends the existing collection (I.e. Calling replaceSubrange).
> 
> If I understand you correctly, it will not be possible to initialise a generic RRC any more, will it? Because that RRC may need additional information (e.g. A maximum buffer size if it stores its data in multiple discrete buffers) which you can’t provide generically.
> 
> Maybe we could have a true copy-constructor instead? That is, replace init<C:Collection>(_:) with init(_: Self), so that it could take any additional arguments from that other instance?

A copying initialiser could work, but it should probably have a parameter for the type of copy to create (empty, shallow copy and deep copy for example), as I suspect it's the empty copy that RangeReplaceableCollection needs more than anything. Otherwise it shouldn't need initialisers on the protocol. This however is something that could (and should) be moved out into its own protocol I think, with RangeReplaceableCollection simply conforming that.


More information about the swift-evolution mailing list