public function test_fix() { $actual = Functools::fix(function ($rec) { return function ($n) use($rec) { return $n == 0 ? 1 : $n * $rec($n - 1); }; }); $this->assertEquals(120, $actual(5)); }
/** I combinator */ public static function i($a) { $_ = self::getInstance(); $s = [$_, 's']; /** @var callable $s */ $k = f::curry([$_, 'k']); return $s($k, $k, $a); }
public function test_ArrayImpl() { $expected = 110; $actual = a_::chain(a_::range(1, 11))->map(f::op('*', [2]))->sum(); $this->assertEquals($expected, $actual); }
public function test_cons() { $expected = new Cons("foo", new Cons("bar", new Cons("buz", null))); $actual = f::cons("foo", f::cons("bar", f::cons("buz", null))); $this->assertEquals($expected, $actual); }
public function test_functools_wrapper() { $f = function () { }; $this->assertEquals(f::arity('explode'), _::arity('explode')); $this->assertEquals(f::tuple('hoge'), _::tuple('hoge')); $this->assertEquals(f::cons("a", "b"), _::cons("a", "b")); $this->assertEquals(f::curry($f), _::curry($f)); $this->assertEquals(f::fix($f), _::fix($f, $f)); $this->assertEquals(f::compose($f, $f), _::compose($f, $f)); }