function test() { $f = new F(); $this->assertSame([], $f->filter($f->odd, [])); $this->assertSame([1], $f->filter($f->odd, [0, 1, 2])); $this->assertSame([0, 2], $f->filter($f->complement($f->odd), [0, 1, 2])); }
function test() { $f = new F(); $this->assertTrue($f->even(2)); $this->assertTrue($f->every($f->even, [])); $this->assertTrue($f->every($f->even, [2])); }
function test() { $f = new F(); $this->assertSame(-1, $f->sub(1)); $this->assertSame(1, $f->sub(3, 2)); $this->assertSame(0, $f->sub(3, 2, 1)); }
function test() { $f = new F(); $comp = $f->comp($f->even, $f->inc); $this->assertTrue($comp(1)); $this->assertSame([true, false], $f->map($f->comp($f->even, $f->inc), [1, 2])); }
function test() { $f = new F(); $this->assertSame(0, $f->add()); $this->assertSame(1, $f->add(1)); $this->assertSame(3, $f->add(1, 2)); $this->assertSame(6, $f->add(1, 2, 3)); }
function test() { $f = new F(); $this->assertEquals(0, $f->reduce($f->add, [])); $this->assertEquals(1, $f->reduce($f->add, [1])); $this->assertEquals(2, $f->reduce($f->add, 1, [1])); $this->assertEquals(3, $f->reduce($f->add, 1, [1, 1])); }
function test() { $f = F::getInstance(); $getName = $f->partial($f->get, 'name'); $this->assertEquals('Alice', $getName(['name' => 'Alice'])); $this->assertEquals(['Bob', null], $f->map($getName, [['name' => 'Bob'], null])); }
function test() { $f = F::getInstance(); $this->assertTrue($f->odd(1)); $this->assertFalse($f->odd(2)); $this->assertSame([true, false, true], $f->map($f->odd, [1, 2, 3])); }
function test() { $f = F::getInstance(); $this->assertEquals(1, $f->mul()); $this->assertEquals(6, $f->mul(2, 3)); $this->assertEquals(-6, $f->mul(2, 3, -1)); }
function test() { $f = F::getInstance(); $this->assertEquals($f->div(2), 0.5); $this->assertEquals($f->div(3, 2), 1.5); $this->assertEquals($f->div(10, 2, 5), 1); }
function test() { $f = new F(); $this->assertSame([], $f->concat()); $this->assertSame([], $f->concat([])); $this->assertSame([], $f->concat([], [])); $this->assertSame([1, 2, 3], $f->concat([1], [2, 3])); $this->assertSame([1, 2, 3, 4, 5], $f->concat([1], [2, 3], [4, 5])); }
function test() { $f = new F(); $this->assertEquals(1, $f->rem(10, 3)); }
function test() { $f = F::getInstance(); $this->assertSame([4, 7], $f->map($f->add, [1, 2], [3, 5])); $this->assertSame([2, 3], $f->map($f->inc, [1, 2])); }
<?php $setup = function () { return [100000, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], \f\F::getInstance()]; }; run('map', $setup, function ($args) { list($n, $array, $f) = $args; for ($i = 0; $i < $n; $i++) { $f->map($f->inc, $array); } }); run('array_map', $setup, function ($args) { list($n, $array, $f) = $args; for ($i = 0; $i < $n; $i++) { array_map($f->inc, $array); } });
function test() { $f = new F(); $this->assertSame(6, $f->apply($f->add, [1, 2, 3])); $this->assertSame(0, $f->apply($f->add, [])); }
function test() { $f = new F(); $this->assertEquals(['value'], $f->vals(['key' => 'value'])); }
function test() { $f = F::getInstance(); $this->assertEquals($f->some($f->even, [1, 2, 3]), 2); $this->assertNull($f->some($f->even, [1, 5, 3])); }
function test() { $f = F::getInstance(); $this->assertSame(false, $f->first([])); $this->assertSame(1, $f->first([1, 2])); }
function test() { $f = F::getInstance(); $this->assertEquals(['key'], $f->keys(['key' => 'value'])); }
function test() { $f = F::getInstance(); $this->assertSame(false, $f->last([])); $this->assertEquals(2, $f->last([1, 2])); }