Reducing::reduce()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\ImmutableCollection;
6
7
use function array_reduce;
8
use Closure;
9
10
/**
11
 * Behaviour to allow "reducing" the immutable collection.
12
 *
13
 * Provides access to reduction behaviour in the form of a method that
14
 * returns a reduced value based on the original collection.
15
 *
16
 * @package Stratadox\Collection
17
 * @author  Stratadox
18
 */
19
trait Reducing
20
{
21
    /**
22
     * @see Reducible::reduce()
23
     * @param Closure $function
24
     * @param mixed   $initial
25
     * @return mixed
26
     */
27
    public function reduce(Closure $function, $initial = null)
28
    {
29
        return array_reduce($this->items(), $function, $initial);
30
    }
31
32
    /** @see Collection::items() */
33
    abstract public function items(): array;
34
}
35