Skip to content

Instantly share code, notes, and snippets.

@iansltx iansltx/gen.php
Last active Jul 14, 2016

Embed
What would you like to do?
Generator Scratchpad
<?php
function gen($arg1) {
var_dump($b = yield $arg1 + 1);
var_dump($d = yield $b + 2);
$ret = $d + 2;
var_dump($ret);
return $ret;
}
var_dump($g = gen(1));
var_dump($a = $g->current());
var_dump($c = $g->send($a + 1));
var_dump($e = $g->send($c + 1));
var_dump($g->getReturn());
<?php
function innerGen()
{
yield 2;
yield 3;
}
function outerGen()
{
yield 1;
yield from innerGen();
}
foreach (outerGen() as $yielded) {
var_dump($yielded);
}
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.