Exemplo n.º 1
0
 /**
  * @dataProvider provideFilter
  */
 public function testFilter($coll)
 {
     $calls = array();
     $result = f\filter(function ($v) use(&$calls) {
         $calls[] = func_get_args();
         return is_int($v);
     }, $coll);
     $this->assertSame(array(10, 30), $result);
     $this->assertSame(array(array(10), array('20'), array(30)), $calls);
 }
Exemplo n.º 2
0
function benchmark_compares()
{
    $number = 100;
    $array = range(1, $number);
    return ['map' => ['array_map' => function () use($array) {
        array_map(function () {
        }, $array);
    }, 'f/map' => function () use($array) {
        f\map(function () {
        }, $array);
    }], 'reduce' => ['array_reduce' => function () use($array) {
        array_reduce($array, function ($a, $b) {
            return $a + $b;
        });
    }, 'f/reduce' => function () use($array) {
        f\reduce(function ($a, $b) {
            return $a + $b;
        }, $array);
    }], 'filter' => ['array_filter' => function () use($array) {
        array_filter($array, function ($v) {
            return $v % 2;
        });
    }, 'f/filter' => function () use($array) {
        f\filter(function ($v) {
            return $v % 2;
        }, $array);
    }], 'rename_keys' => ['raw' => function () use($array) {
        $result = array();
        foreach ($array as $key => $v) {
            $result['a' . $key] = $v;
        }
    }, 'f\\rename_keys' => function () use($array) {
        f\rename_keys($array, f\map(function ($k) {
            return 'a' . $k;
        }, $array));
    }]];
}
Exemplo n.º 3
0
/**
 * f\remove($fn, $coll)
 *
 * Returns a new collection with the values that applied to fn are false.
 *
 * f\remove(function ($value) { return $value % 2 == 0; }, range(1, 6));
 * => array(1, 3, 5)
 */
function remove($fn, $coll)
{
    return f\filter(f\complement($fn), $coll);
}