-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Description
| Previous ID | SR-3762 |
| Radar | rdar://problem/26476285 |
| Original Reporter | @airspeedswift |
| Type | Improvement |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Standard Library |
| Labels | Improvement, AffectsABI, StarterProposal |
| Assignee | None |
| Priority | Medium |
md5: 0a15e4ebe05ad3320d3ce0d815461616
Issue Description:
There should be a default implementation for Collections whose Index type is Int. This make it more convenient to write integer indexed collections. In the previous collections model it was just understood that an Int index’s successor was the integer + 1 and there was no boilerplate a developer had to write.
extension Collection where Index: Integer {
public func index(after i: Index) -> Index {
return i + 1
}
}
Note, this would mean that collections that did not want this behavior (say, they used a non-unit stride) would need to remember to override this. However, since users can just do integer calculations themselves without using the collection, it would probably be wise for these types to create an opaque index type to wrap the integer in anyway.
This would need an evolution proposal. Part of the initial pitch should include whether this should be done to just Collection or be specific to RandomAccessCollection.