At its core, query is a monad, and we can make it more expressive and less reliant on manually rolled iterators if we add the `flatMap` method.