Previously on Point-Free we spent several episodes exploring the topic of randomness. It’s a topic that seems at odds with functional programming. We like to work with functions that take data in and spit data out in a consistent fashion, but randomness is all about inconsistency!
Despite this seemingly irreconcilable difference, we found that a randomness API deeply benefited from functional programming principles, specifically composition. We were able to distill the idea of randomness into a single type that could be transformed and combined using familiar functional concepts, and we ended up with a little library that was much more flexible and extensible than the randomness APIs that ship with Swift.
But even though we built this library around functional principles, it’s far from functional. We’d be remiss to ignore the fact that it’s completely unpredictable and untestable, and any code that uses it becomes immediately unpredictable and untestable as a result! One of the things we value in functional programming is the ability to reason about our code using predictable units that can be easily tested, so today we’re going to do something about it: we’re going to make the untestable testable.