I think it would be much better to extend all Collections with the means to get the offset of a given index, and an index at a given offset. Such as:
and a corresponding offset(of: Index) -> Int
method as well. Way out of scope for 5.0 at this point.
Reasons I kept this on String.Index:
- It's a off-ramp for misuses of
encodedOffset
which is already on String.Index.
- String.Index is an infrequent namespace; if we had to pollute something that will be superseded in the future, better in an infrequent namespace.
- It's name wouldn't conflict with a more general addition to all Collections.
1 Like