A generator, duck typing, and a branchless conditional walk into a bar.
At codegolf.stackexchange.com, smaller is better.