Skip to content

Instantly share code, notes, and snippets.

@iansltx
Last active July 14, 2016 22:49
Show Gist options
  • Save iansltx/bb7d1fc9ef0f155bc5d26d79a5c95f11 to your computer and use it in GitHub Desktop.
Save iansltx/bb7d1fc9ef0f155bc5d26d79a5c95f11 to your computer and use it in GitHub Desktop.
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