[swift-users] How to be DRY on ranges and closed ranges?

Ole Begemann ole at oleb.net
Thu Oct 13 13:54:09 CDT 2016

> The more idiomatic way is to look at API design in a new way. Note these
> points:
> 1. `Countable` variant is preferred when you want to deal with integer
> ranges as it more closely matches the element type.
> 2. Both countable range variants share a common protocol conformance
> already: `RandomAccessCollection`
> 3. Swift API design prefers member functions to free functions.
> Hence a more idiomatic (Swifty) API would probably be something like this:

Thanks for sharing this solution, Hooman, I really like it. I think 
you're making a great point about considering the appropriate 
abstraction for an algorithm, which is why I blogged about this: 

I hope you don't mind.


More information about the swift-users mailing list