Iterator pattern of TypeScript