At today’s iOS Breakfast coding session I decided to build simple Swift framework that helps compute precise probabilities. I had been thinking about this for a while and I wanted to see what it would look like in Swift.

As John Gruber and Guy English lament on The Talk Show, languages with operator overloading can be abused. However, if you use your overloads for doing actual math operations on well defined types, the results can be quite elegant.

I wanted a some simple methods that would let me compute, for example, the odds of drawing an ace of diamonds, in a poker hand. The odds are 5/52. Here is a unit test using the framework available on Github that shows how this can be computed.