Class UnfoldIterator
An iterator that can be used to generate nested iterators out of a collection of items by applying an function to each of the elements in this iterator.
Property Summary
-
$_innerIterator protected
Traversable
A reference to the internal iterator this object is wrapping.
-
$_unfolder protected
callable
A function that is passed each element in this iterator and must return an array or Traversable object.
Method Summary
-
__construct() public
Creates the iterator that will generate child iterators from each of the elements it was constructed with.
-
getChildren() public
Returns an iterator containing the items generated by transforming the current value with the callable function.
-
hasChildren() public
Returns true as each of the elements in the array represent a list of items
Method Detail
__construct() ¶ public
__construct(Traversable $items, callable $unfolder)
Creates the iterator that will generate child iterators from each of the elements it was constructed with.
Parameters
-
Traversable
$items The list of values to iterate
-
callable
$unfolder A callable function that will receive the current item and key. It must return an array or Traversable object out of which the nested iterators will be yielded.
getChildren() ¶ public
getChildren(): RecursiveIterator
Returns an iterator containing the items generated by transforming the current value with the callable function.
Returns
RecursiveIterator
hasChildren() ¶ public
hasChildren(): bool
Returns true as each of the elements in the array represent a list of items
Returns
bool