Closed rybakit closed 6 years ago
Since generators are a PHP 5.5 feature I personally don't see any reason not to do this.
@eFrane I can't come up with a good idea of how to integrate generators into the current api. For example, lets say you packed the following array:
$array = [range(1, 9), 'foobar'];
How to unpack it using generators then? You need to do something like:
function read_result($result, callable $callback)
{
if (!$result instanceof \Traversable) {
return $callback($result);
}
foreach ($result as $item) {
read_result($item, $callback);
}
}
$raw = $unpacker->unpack();
read_result($raw, function ($item) { var_dump($item); });
And you probably don't want to do this on every unpack call.
New type transformers introduced in PR #21 address the issue:
E.g.: