Implement generator with recursion