<?php function gen(int $x) { $x = yield $x + 1; $x = yield $x + 2; $x = yield $x + 3; $x = yield $x + 4; } $gen = gen(5); $assertions = [ ['expect' => 6], ['send' => 1, 'expect' => 3], ['send' => 5, 'expect' => 8], ['send' => 3, 'expect' => 7], ]; foreach($assertions as $assertion) { if(!array_key_exists('send', $assertion)) { echo '(Received / Initial Assertion / Whatever) ' . $gen->current() . PHP_EOL; continue; } echo $assertion['expect'] . ' === ' . $gen->send($assertion['send']) . PHP_EOL; }
You have javascript disabled. You will not be able to edit any code.