Generic generator/iterator pattern