memory efficient enumeration that uses continuation passing style