SE-0270: Add Collection Operations on Noncontiguous Elements


nnnnnnnn
Nate Cook

    November 12

dabrahams:
RangeSet is documented as “a set of ranges of any Comparable value.” I believe that is a proper description of its non-mutating semantics. That means that the elements of the set are ranges.

RangeSet is the set of all the values in its constitutive ranges, where the values can be of any Comparable type — integers, floats, strings, collection indices, etc.

So it’s a set of comparable elements, not a set of ranges :exploding_head: I guess the fact that I interpreted it the other way means this proposal needs some editing and clarification! This also explains (along with the fact that I overlooked that part of the proposal) why we're on different pages about constituent empty ranges.

Likewise, RangeSet has no notion of containing empty Ranges, because empty ranges represent no values in T. Inserting an empty range therefore never has an effect on a RangeSet.

In that case, IMO it's clear that the insert that takes a range ought to be spelled something like s.insert(allIn: range), and other APIs should be similarly reconsidered.

-Dave

6 Likes