14use UnexpectedValueException;
49 if ( is_array( $iter ) ) {
50 $baseIterator =
new ArrayIterator( $iter );
51 } elseif ( $iter instanceof Iterator ) {
52 $baseIterator = $iter;
54 throw new UnexpectedValueException(
"Invalid base iterator provided." );
56 parent::__construct( $baseIterator );
58 $this->aCallback = $options[
'accept'] ??
null;
61 public function next(): void {
67 $this->rewound = true;
73 $inner = $this->getInnerIterator();
74 '@phan-var Iterator $inner';
75 $value = ( $this->vCallback )( $inner->current() );
76 $ok = ( $this->aCallback ) ? ( $this->aCallback )( $value ) : true;
78 $this->cache[
'current'] = $value;
85 #[\ReturnTypeWillChange]
86 public function key() {
95 return parent::valid();
99 #[\ReturnTypeWillChange]
102 if ( parent::valid() ) {
103 return $this->cache[
'current'];
113 if ( !$this->rewound ) {
120class_alias( MappedIterator::class,
'MappedIterator' );