mirror of
https://github.com/php/php-src.git
synced 2026-04-24 16:38:25 +02:00
1c09c0c832
Co-authored-by: Gina Peter Banyard <girgias@php.net> Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com> Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
31 lines
367 B
PHP
31 lines
367 B
PHP
--TEST--
|
|
Generators
|
|
--FILE--
|
|
<?php
|
|
|
|
function producer(): \Generator {
|
|
yield 1;
|
|
yield 2;
|
|
yield 3;
|
|
}
|
|
|
|
function map_incr(iterable $it): \Generator {
|
|
foreach ($it as $val) {
|
|
yield $val +1;
|
|
}
|
|
}
|
|
|
|
$result = producer() |> map_incr(...) |> iterator_to_array(...);
|
|
|
|
var_dump($result);
|
|
?>
|
|
--EXPECT--
|
|
array(3) {
|
|
[0]=>
|
|
int(2)
|
|
[1]=>
|
|
int(3)
|
|
[2]=>
|
|
int(4)
|
|
}
|