SE-0270 (Review #3): Add Collection Operations on Noncontiguous Elements

I advocated for embracing subrange in this revision of the proposal in large part because of your observation that "subrange" is the existing term of art for "a range of positions in a collection":

A subrange is not "a range of elements in a collection":

  1. Swift already has SubSequence and Slice for that.
  2. If it were, removeSubrange wouldn't be any clearer than removeRange.

I think of "subrange" now as "a range of positions that represent consecutive elements in a collection". So numbers.subranges { $0.isMultiple(of: 2) } is returning "the positions of the elements that are a multiple of 2".

I think there's a lot of nice synergy with removeSubrange(_:) and replaceSubrange(_:with:) in naming the algorithms subranges(where:), removeSubranges(_:), and moveSubranges(_:to:). (Also I imagine we'll be adding moveSubrange(_:to:) soon, in a follow up proposal.)

1 Like