The problem

Seen ? A Generator is not countable, we know it, and it’s logical.
How would you count something that is not yet generated?
Well, sometimes you know.
You can know the number of elements, and use yield to avoid putting everything in memory at once.

Now what ? Based on the emptiness of the result, I need to make different stuff.
Why using lazy Generators if you end up putting everything into memory (yes, iterator_to_array) ?

The hack

The only solution I found is to throw an exception in the function that yields based on its knowledge,
and instead of checking emptiness of the result, I try/catch.