> On 17 Feb 2017, at 01:39, Ben Cohen via swift-evolution > <swift-evolution@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?
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution