[swift-evolution] Dropping Comparable requirement for indices

Tino Heth 2th at gmx.de
Fri Jul 8 15:53:07 CDT 2016


Right now I'm working on a lib for charts/plots, and I choose to create a custom interval-type that has no comparable requirement.
Of course, as soon as I leave the completely abstract and generic world, I need to bring things into an order — but if this order has to be defined by a global function "<", there is a loss in flexibility.
My plan is to use "<" as a default wherever possible to define my ranges, with the option to change it to a custom alternative; maybe similar reasoning can be applied to the index-problem.

Tino

Real world example:
Let's assume I want to create a bar-chart to compare the population of several countries.
There is no natural order for countries (I hope we can agree on that ;-), so no matter how I'd model them, it would feel wrong to define "<":
Sort by name might be the most obvious choice, but it could also be the size, the timezone, average income, the peak hight of its highest mountain...
Additionally, I might want to use different orders for different charts, which is only possible when I can change the function which dictates the order.


More information about the swift-evolution mailing list