File: D:/HostingSpaces/SBogers10/reiskick.komma.nl/vendor/lstrojny/functional-php/src/Functional/Map.php
<?php
/**
* @package Functional-php
* @author Lars Strojny <lstrojny@php.net>
* @copyright 2011-2017 Lars Strojny
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/lstrojny/functional-php
*/
namespace Functional;
use Functional\Exceptions\InvalidArgumentException;
use Traversable;
/**
* Produces a new array of elements by mapping each element in collection through a transformation function (callback).
* Callback arguments will be element, index, collection
*
* @param Traversable|array $collection
* @param callable $callback
* @return array
*/
function map($collection, callable $callback)
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
$aggregation = [];
foreach ($collection as $index => $element) {
$aggregation[$index] = $callback($element, $index, $collection);
}
return $aggregation;
}