[swift-evolution] Sequence/Collection Enhancements
Ole Begemann
ole at oleb.net
Mon Feb 20 09:38:39 CST 2017
> On 17 Feb 2017, at 01:39, Ben Cohen via swift-evolution <swift-evolution at swift.org> wrote:
>
> Hi swift-evolution,
>
> Following up on Ted’s post regarding the opening up of stage 2, I’m starting a thread to discuss additive algorithms for Sequence and Collection.
>
> Here is a list of commonly requested algorithms to operate on Sequence or Collection:
>
> In-place transformations:
> transform elements in a MutableCollection using a closure i.e. in-place map
> remove(where:) that takes a predicate i.e. in-place filter
> remove(indices:) that takes a Sequence of Index
Is it possible to implement this (efficiently) with RangeReplaceableCollection's current feature set? Since replaceSubrange(_:with:) potentially invalidates indices, you can't call it repeatedly and expect that the passed-in indices are still valid.
I suppose it's possible to create a new empty collection, then iterate over the existing collection's indices and append each element that doesn't match one of the indices to be removed, but that sounds a bit awkward to me. Is there a better solution?
> bulk operations (replace, remove, insert) on RangeReplaceableCollection for a Sequence of subranges
This relates to my question above. Is there a better way to implement this than creating an new empty collection and iterating over the existing elements, replacing/skipping/inserting at the passed-in subranges?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170220/47b4bd52/attachment.html>
More information about the swift-evolution
mailing list