mediawiki-extensions-Echo/includes/iterator/CallbackIterator.php
Aryeh Gregor 3af6a04c69 Use IteratorDecorator from core
As far as I can tell, EchoIteratorDecorator is functionally identical to
IteratorDecorator from includes/libs/iterators/ in core, so why have a
separate copy? (EchoIteratorDecorator does pass through the return value
of next() or rewind(), if any, but there shouldn't be any per the
Iterator interface.)

Change-Id: Ic763ec19c15f67d9c9b42ebffb88c52b9056ed22
2022-05-02 13:44:41 +03:00

19 lines
419 B
PHP

<?php
/**
* Applies a callback to all values returned from the iterator
*/
class EchoCallbackIterator extends IteratorDecorator {
/** @var callable */
protected $callable;
public function __construct( Iterator $iterator, $callable ) {
parent::__construct( $iterator );
$this->callable = $callable;
}
public function current() {
return call_user_func( $this->callable, $this->iterator->current() );
}
}