> On Sep 8, 2017, at 6:03 PM, Xiaodi Wu via swift-evolution > <[email protected]> wrote: > > For any open protocol (i.e., a protocol for which the universe of possible > conforming types cannot be enumerated a priori by the protocol designer) > worthy of being a protocol by the Swift standard ("what useful thing can you > do with such a protocol that you could not without?"), any sufficiently > interesting requirement (i.e., one for which user ergonomics would measurably > benefit from a default implementation) either cannot have a universally > guaranteed correct implementation or has an implementation which is also > going to be the most performant one (which can therefore be a non-overridable > protocol extension method rather than an overridable protocol requirement > with a default implementation).
Counter-example: `index(of:)`, or rather, the underscored requirement underlying `index(of:)`. The "loop over all indices and return the first whose element matches" default implementation is universally guaranteed to be correct, but a collection like `Set` or `SortedArray` can provide an implementation which is more performant than the default. -- Brent Royal-Gordon Architechies
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
