Sorted Collection Protocol

Nice, I implemented your suggestions here and it made the code a lot simpler.

1

I did this, but my implementation recalculates count for every slice, which will be expensive for non-random-access collections; I think there are ways around this though. We should probably run some benchmarks to see which implementation is most efficient. But we need an ordered non-random-access collection type, and the only ones I can think of in the Standard Library are String and it's views, and it doesn't make much sense to sort those like DefaultIndices<String>, though it doesn’t support duplicate elements.

2

But a conforming type can override this, like SortedArray does. Or maybe it is better to require conforming types to explicitly implement this, instead of doing it automatically?

4

I added remove methods to SortedArray (and it has an empty initialiser), but I think only methods that can take advantage of the fact that the elements are sorted belong in the SortedCollection and MutableSortedCollection protocols. Like remove(Element) and remove(all: Element).

Note: MutableSortedCollection probably needs a better name, as it is nothing like MutableCollection.