예제 #1
0
 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));
 }
예제 #2
0
 /** I combinator */
 public static function i($a)
 {
     $_ = self::getInstance();
     $s = [$_, 's'];
     /** @var callable $s */
     $k = f::curry([$_, 'k']);
     return $s($k, $k, $a);
 }
예제 #3
0
 public function test_ArrayImpl()
 {
     $expected = 110;
     $actual = a_::chain(a_::range(1, 11))->map(f::op('*', [2]))->sum();
     $this->assertEquals($expected, $actual);
 }
예제 #4
0
 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);
 }
예제 #5
0
 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));
 }