예제 #1
0
 function testMapMulti()
 {
     $a = array(1, 2, 3);
     $b = array("one", "two", "three");
     $this->assertEquals(array(array(1, "one"), array(2, "two"), array(3, "three")), iterator_to_array(itertools\map(function ($a, $b) {
         return array($a, $b);
     }, itertools\to_iterator($a), itertools\to_iterator($b))));
 }
예제 #2
0
파일: FileTask.php 프로젝트: chh/bob
 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;
 }
예제 #3
0
 /**
  *
  */
 public function testMapMoreIterable()
 {
     $lambda = function (...$args) {
         return call_user_func('array_sum', $args);
     };
     $a = [1, 2, 3, 4];
     $b = [17, 12, 11, 10];
     $c = [-1, -4, 5, 9];
     $twoIterable = map($lambda, $a, $b);
     $threeIterable = map($lambda, $a, $b, $c);
     $this->assertSame([18, 14, 14, 14], to_array($twoIterable));
     $this->assertSame([17, 10, 19, 23], to_array($threeIterable));
 }
예제 #4
0
파일: Collection.php 프로젝트: chh/funk
 function map($callback)
 {
     $this->iterator = itertools\map($callback, $this->getIterator());
     return $this;
 }