Created
May 17, 2017 16:55
-
-
Save copperwall/5a6b1c27d4095724e23a44663bc3f1be to your computer and use it in GitHub Desktop.
Lazy Evaluation
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
<?php | |
// User Generator | |
function getGuideAuthors(int $guideid): Iterator { | |
// Guide::getUserids could be a generator too! | |
foreach (Guide::getUserids($guideid) as $userid) { | |
// Yield full ORM object. | |
yield User::get($userid); | |
} | |
} | |
function notifyUser(int $guideid, Iterator $users): void { | |
$guide = Guide::get($guideid); | |
if (!$guide->public) { | |
// If the guide isn't public, no Users are generated. | |
return; | |
} | |
foreach ($users as $user) { | |
sendNotification('stuff', $user); | |
} | |
} | |
$authorGen = getGuideAuthors(13470); | |
notifyUsers(13470, $authorGen); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment