public function testReducing() { $instance = Collectors::reducing(1, function ($a, $b) { return $a * $b; }); $instance->add("foo", 2); $instance->add("bar", 3); $instance->add("baz", 4); $this->assertEquals(24, $instance->get()); }
/** * Get a collector that concatenates all the elements in the stream. * * @param string $delimiter [optional] A delimiter to insert between * elements. Defaults to the empty string. * @return Collector */ public static function joining($delimiter = "") { $first = true; return Collectors::reducing("", function ($current, $element) use(&$first, $delimiter) { if (!$first) { $current .= $delimiter; } else { $first = false; } return $current . $element; }); }