A generator, duck typing, and a branchless conditional walk into a bar.
Grab a piece of paper and try to fold your way out of this problem.