/** * */ public function testFilterIterator() { $toFilter = [0, 1, 2, 3, 4, 5]; $callback = function ($i) { return $i <= 3; }; $filtered = to_array(filter($callback, $toFilter)); $this->assertSame([0, 1, 2, 3], $filtered); $filtered = to_array(filter_false($callback, $toFilter)); $this->assertSame([4, 5], $filtered); }
function getTimestamp() { $lastModifiedTimes = iterator_to_array(itertools\filter(itertools\map(function ($file) { if (file_exists($file)) { return @filemtime($file); } }, $this->prerequisites))); if ($lastModifiedTimes) { return max($lastModifiedTimes); } return 0; }
function getTaskPrerequisites() { $app = $this->application; return itertools\filter(itertools\to_iterator($this->prerequisites), function ($task) use($app) { return $app->taskDefined($task); }); }
function remove($predicate) { $this->iterator = itertools\filter($this->getIterator(), static::identityFn($predicate, true)); return $this; }
function testFilterWithoutArgumentRemovesFalsyElements() { $a = new ArrayIterator(array(1, 2, null, 3, 0, false)); $this->assertEquals(array(1, 2, 3), iterator_to_array(itertools\filter($a), false)); }