55 if ( is_array( $iter ) ) {
56 $baseIterator =
new ArrayIterator( $iter );
57 } elseif ( $iter instanceof Iterator ) {
58 $baseIterator = $iter;
60 throw new UnexpectedValueException(
"Invalid base iterator provided." );
62 parent::__construct( $baseIterator );
64 $this->aCallback = $options[
'accept'] ??
null;
67 public function next(): void {
73 $this->rewound =
true;
79 $inner = $this->getInnerIterator();
80 '@phan-var Iterator $inner';
81 $value = call_user_func( $this->vCallback, $inner->current() );
82 $ok = ( $this->aCallback ) ? call_user_func( $this->aCallback, $value ) :
true;
84 $this->cache[
'current'] = $value;
90 #[\ReturnTypeWillChange]
91 public function key() {
100 return parent::valid();
103 #[\ReturnTypeWillChange]
106 if ( parent::valid() ) {
107 return $this->cache[
'current'];
117 if ( !$this->rewound ) {
Convenience class for generating iterators from iterators.
__construct( $iter, $vCallback, array $options=[])
Build an new iterator from a base iterator by having the former wrap the later, returning the result ...
init()
Obviate the usual need for rewind() before using a FilterIterator in a manual loop.