[swift-evolution] [Proposal] Decoupling Floating Point Strides from Generic Implementations

Brent Royal-Gordon brent at architechies.com
Tue Mar 1 04:56:56 CST 2016

> If one were looking for a quick and dirty fix, the same kind of math used in this rough solution (let value = start + count * interval) could be adopted back into the current generic implementation.

I notice that `start + count * interval` would actually work with `Int`, too.

I wonder if we might be better off introducing a sub-protocol of `Strideable` which can advance several increments at a time:

	protocol RandomStrideable: Strideable {
		func advancedBy(n: Self.Distance, times: Int) -> Self
	extension RandomStrideable {
		func stride(to end: Self, by: Distance) -> RandomStrideTo<Self> { ... }
		func stride(through end: Self, by: Distance) -> RandomStrideThrough { ... }

`Double` and `Int` can both conform to `RandomStrideable`; types which cannot do this (*are* there any types which cannot do this?) can conform to `Strideable`.

Alternatively, if we actually *prefer* the repeated-advance implementation and we're only using this multiplication-based one because we have to, `Strideable` can be the new multiplication-based protocol and `IncrementalStrideable` can be a subprotocol which supports repeated-advance.

Brent Royal-Gordon

More information about the swift-evolution mailing list