for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of graze/data-file
*
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* @license https://github.com/graze/data-file/blob/master/LICENSE.md
* @link https://github.com/graze/data-file
*/
namespace Graze\DataFile\Helper;
use IteratorIterator;
use Traversable;
class MapIterator extends IteratorIterator
{
* Function to apply to each iterated element
* @var callable
private $callable;
* MapIterator constructor.
* @param Traversable $iterator
* @param callable $callable
public function __construct(Traversable $iterator, callable $callable)
parent::__construct($iterator);
$this->callable = $callable;
}
* Get the value of the current element
public function current()
$iterator = $this->getInnerIterator();
return call_user_func($this->callable, $iterator->current(), $iterator->key(), $iterator);