예제 #1
0
파일: f.php 프로젝트: ihor/Nspl
/**
 * @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;
}
예제 #2
0
파일: ATest.php 프로젝트: ihor/Nspl
 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)));
 }