Created
February 19, 2014 21:40
-
-
Save asm89/9102248 to your computer and use it in GitHub Desktop.
Generators in HHVM and PHP
This file contains hidden or 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 xs() { | |
$i = 0; | |
while (true) { | |
yield $i++; | |
} | |
} | |
$xs = xs(); | |
var_dump($xs->valid()); | |
var_dump($xs->current()); |
This file contains hidden or 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 xs() { | |
$i = 0; | |
while (true) { | |
yield $i++; | |
} | |
} | |
$xs = xs(); | |
var_dump($xs->next()); | |
var_dump($xs->valid()); | |
var_dump($xs->current()); |
This file contains hidden or 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 xs() { | |
$i = 0; | |
while (true) { | |
yield $i++; | |
} | |
} | |
$xs = xs(); | |
$xs->send(42); | |
var_dump($xs->next()); | |
var_dump($xs->valid()); | |
var_dump($xs->current()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment