public function testReduce() { $a = function () { (yield 1); (yield 2); (yield 3); }; $add = function ($a, $b) { return $a + $b; }; $this->assertEquals(16, P::reduce($add, 10, $a())); $reduceByAdding = P::reduce($add, 0); $this->assertEquals(6, $reduceByAdding($a())); $b = ['a' => 1, 'b' => 2]; $concatKeyVals = function ($acc, $value, $key) { return $acc . (string) $key . (string) $value; }; $this->assertEquals('a1b2', P::reduce($concatKeyVals, '', $b)); }