Skip to content

Instantly share code, notes, and snippets.

@asm89
Created February 19, 2014 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asm89/9102248 to your computer and use it in GitHub Desktop.
Save asm89/9102248 to your computer and use it in GitHub Desktop.
Generators in HHVM and PHP
<?php
function xs() {
$i = 0;
while (true) {
yield $i++;
}
}
$xs = xs();
var_dump($xs->valid());
var_dump($xs->current());
<?php
function xs() {
$i = 0;
while (true) {
yield $i++;
}
}
$xs = xs();
var_dump($xs->next());
var_dump($xs->valid());
var_dump($xs->current());
<?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