Files
sqrtspace-php/src/Streams/Iterators/MapIterator.php
2025-07-20 04:08:08 -04:00

27 lines
563 B
PHP

<?php
namespace SqrtSpace\SpaceTime\Streams\Iterators;
/**
* Iterator that applies a mapping function to each element
*/
class MapIterator extends \FilterIterator
{
private $callback;
public function __construct(\Iterator $iterator, callable $callback)
{
parent::__construct($iterator);
$this->callback = $callback;
}
public function accept(): bool
{
return true; // Accept all elements
}
public function current(): mixed
{
return ($this->callback)(parent::current());
}
}