TestLanguage.php 517 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. class TestLanguage extends TestCase
  4. {
  5. public function testYield()
  6. {
  7. $checker = function ($val) {
  8. return $val > 5 ? true : false;
  9. };
  10. $map_adder = function ($datas,$delta)
  11. {
  12. foreach ($datas as $val) {
  13. $k = yield $val + $delta;
  14. }
  15. };
  16. $datas = [1,2,3,4,5,6];
  17. $x = $map_adder($datas,2);
  18. foreach ($x as $v) {
  19. $t = $checker($v);
  20. }
  21. }
  22. }