Iteration primitives using generators