Last active
July 14, 2016 22:49
-
-
Save iansltx/bb7d1fc9ef0f155bc5d26d79a5c95f11 to your computer and use it in GitHub Desktop.
Generator Scratchpad
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 | |
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()); |
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 | |
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