Traverse the parser via method chaining

This commit is contained in:
Andrea Marco Sartori 2023-01-14 13:12:49 +10:00
parent 76904d3768
commit bdb20ff836

View File

@ -141,6 +141,21 @@ final class JsonParser implements IteratorAggregate
return $this;
}
/**
* Traverse the lazily iterable JSON
*
* @param Closure|null $callback
* @return void
*/
public function traverse(Closure $callback = null): void
{
$callback ??= fn () => true;
foreach ($this as $key => $value) {
$callback($value, $key);
}
}
/**
* Retrieve the lazily iterable JSON
*