Looks like a useful generic function. Let's bear this in mind and if we use it somewhere else then define it in a `Functions2` class (or some better name).