-
-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathEach.php
More file actions
36 lines (31 loc) · 911 Bytes
/
Copy pathEach.php
File metadata and controls
36 lines (31 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* @package Functional-php
* @author Lars Strojny <lstrojny@php.net>
* @copyright 2011-2021 Lars Strojny
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/lstrojny/functional-php
*/
namespace Functional;
use Functional\Exceptions\InvalidArgumentException;
/**
* Iterates over a collection of elements, yielding each in turn to a callback function. Each invocation of $callback
* is called with three arguments: (element, index, collection)
*
* @template K
* @template V
*
* @param iterable<K,V> $collection
* @param callable(V,K,iterable<K,V>):void $callback
*
* @return void
*
* @no-named-arguments
*/
function each($collection, callable $callback)
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
foreach ($collection as $index => $element) {
$callback($element, $index, $collection);
}
}