public function testCollectionReduceFilter() { $collection = new Collection(array('data' => array(1, 2, 3))); $filter = function ($memo, $item) { return $memo + $item; }; $result = $collection->reduce($filter, 0); $this->assertEqual(6, $collection->reduce($filter, 0)); $this->assertEqual(7, $collection->reduce($filter, 1)); }
/** * Reduce, or fold, a collection down to a single value * * Overridden to load any data that has not yet been loaded. * * @param callback $filter The filter to apply. * @param mixed $initial Initial value * @return mixed A single reduced value */ public function reduce($filter, $initial = false) { if (!$this->closed()) { while ($this->next()) { } } return parent::reduce($filter, $initial); }