Skip to content

Instantly share code, notes, and snippets.

@wrossmann
Created October 9, 2015 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrossmann/780500ce90aa6c9bd3ff to your computer and use it in GitHub Desktop.
Save wrossmann/780500ce90aa6c9bd3ff to your computer and use it in GitHub Desktop.
// a complex iterator
function gen() {
$pagesize = 50;
while( $items = $someapi->paginated_operation($pagesize) ) {
foreach( $items as $item ) {
yield $item;
}
}
}
// hidden by a simple function
foreach(gen() as $item) {
do_a_thing($item);
}
// you could have 50,000 paginated results, but you only fetch a small batch as-needed
// and you only need to expose a function call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment