Created
October 9, 2015 23:23
-
-
Save wrossmann/780500ce90aa6c9bd3ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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