Skip to content

Instantly share code, notes, and snippets.



Created Oct 26, 2015
What would you like to do?
Single generator
$generatorWithTwoWayCommunication = function()
$randomValue = mt_rand();
yield $randomValue;
$receivedFromOuterSpace = yield;
yield $receivedFromOuterSpace * $receivedFromOuterSpace;
return $receivedFromOuterSpace * $randomValue;
$generator = $generatorWithTwoWayCommunication();
$valueFromFirstIteration = $generator->current();
$valueFromSecondIteration = $generator->send(666);
$valueReturnedFromGenerator = $generator->getReturn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.