Passed
Pull Request — master (#19)
by
unknown
02:33
created

AccumulateTrait::accumulate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib\Traits;
8
9
use Zicht\Itertools as iter;
10
11
trait AccumulateTrait
12
{
13
    /**
14
     * Returns an iterator that containing accumulated elements
15
     *
16
     * If the optional $closure argument is supplied, it should be a string:
17
     * add, sub, mul, min, or max.  Or it can be a Closure taking two
18
     * arguments that will be used to instead of addition.
19
     *
20
     * > iter\iterable([1,2,3,4,5])->accumulate()
21
     * 1 3 6 10 15
22
     *
23
     * > iter\iterable(['One', 'Two', 'Three'])->accumulate(function ($a, $b) { return $a . $b; })
24
     * 'One' 'OneTwo' 'OneTwoThree'
25
     *
26
     * @param string|\Closure $closure
27
     * @return iter\lib\AccumulateIterator
28
     */
29 1
    public function accumulate($closure = 'add')
30
    {
31 1
        return iter\accumulate($this, $closure);
32
    }
33
}
34