Whilst I'd love to solve this problem in python, I'm stuck in Delphi for this one. I have nested lists (actually objects with nested lists as properties, but nevermind), and I want to iterate over them in a generator fashion. That is, I want to write a Next function, which gives me the next item from the leaves of the tree described by the nested lists.
For example, lets say I have
[[1,2,3],[4,5],[],[6],[7,8]]
I want 8 consecutive calls to Next() to return 1..8.
How can I do this in a language without yield and generators?
Note that the depth of the nesting is fixed (2 in this example, 4 in real life), but answers which solve the more general case where depth is variable are welcome.
EDIT: Sorry, I should have mentioned, this is Delphi 2007.