/** * @deprecated * @see \nspl\a\filter * * Returns sequence items that satisfy the predicate * * @param callable $predicate * @param array|\Traversable $sequence * @return array */ function filter(callable $predicate, $sequence) { args\expects(args\traversable, $sequence); $sequence = a\traversableToArray($sequence); $filtered = array_filter($sequence, $predicate); return a\isList($sequence) ? array_values($filtered) : $filtered; }
public function testTraversableToArray() { $this->assertEquals([1, 2, 3], traversableToArray([1, 2, 3])); $this->assertEquals([1, 2, 3], traversableToArray(new \nspl\ds\ArrayObject(1, 2, 3))); $this->assertEquals([1, 2, 3], traversableToArray(new \ArrayObject([1, 2, 3]))); $range = function ($min, $max) { for ($i = $min; $i <= $max; ++$i) { (yield $i); } }; $this->assertEquals([1, 2, 3], traversableToArray($range(1, 3))); }