示例#1
0
 public function testAppend()
 {
     $m1 = [1, 2, 3];
     $m2 = [11, 13];
     $m = mappend($m1, $m2);
     $this->assertEquals([1, 2, 3, 11, 13], $m);
 }
示例#2
0
 public function testAppend()
 {
     $m1 = 'abc';
     $m2 = 'def';
     $m = mappend($m1, $m2);
     $this->assertEquals('abcdef', $m);
 }
示例#3
0
 public function testAppend()
 {
     $m = new Func\Unit();
     $m = mappend(new Func\Unit(), new Func\Unit());
     $this->assertEquals(new Func\Unit(), $m);
     $this->assertEquals(new Func\Unit(), mappend($m, mempty()));
     $this->assertEquals(new Func\Unit(), mempty()->mappend(mempty())->mappend($m));
 }
示例#4
0
 public static function mappend($m1, $m2)
 {
     assert($m1 instanceof Instance, 'First argument must be Func');
     assert($m2 instanceof Instance, 'Second argument must be Func');
     return f(function ($f, $g, $a) {
         return mappend($f($a), $g($a));
     }, $m1, $m2);
 }
示例#5
0
 public static function bind($m, callable $f)
 {
     assert($m instanceof Instance, 'First argument must be Writer');
     $inner = $f($m->a);
     if ($inner instanceof \Laiz\Func\Any) {
         $inner = $inner->cast($m);
     }
     return new Instance($inner->a, mappend($m->w, $inner->w));
 }
示例#6
0
 public function testGuardAppend()
 {
     $f = function ($s, ...$eq) {
         return f(function ($s, $a, $b) {
             return fconst($s, guard($a === $b));
         }, $s, ...$eq);
     };
     $at = $f('a', 1, 1);
     $af = $f('a', 1, 2);
     $bt = $f('b', 2, 2);
     $bf = $f('b', 2, 3);
     $this->assertEquals(Just('a'), $at->cast(Nothing()));
     $this->assertEquals(Nothing(), $af->cast(Nothing()));
     $this->assertEquals(Just('b'), $bt->cast(Nothing()));
     $this->assertEquals(Nothing(), $bf->cast(Nothing()));
     $this->assertEquals(Nothing(), mappend($af, $bf)->cast(Nothing()));
     $this->assertEquals(Just('a'), mappend($at, $bf)->cast(Nothing()));
     $this->assertEquals(Just('b'), mappend($af, $bt)->cast(Nothing()));
     $this->assertEquals(Just('ab'), mappend($at, $bt)->cast(Nothing()));
     $this->assertEquals(Nothing(), mappend($f('a', 1), $f('b', 1), 2)->cast(Nothing()));
     $this->assertEquals(Just('a'), mappend($f('a', 2), $f('b', 1), 2)->cast(Nothing()));
     $this->assertEquals(Just('b'), mappend($f('a', 1), $f('b', 2), 2)->cast(Nothing()));
     $this->assertEquals(Just('ab'), mappend($f('a', 2), $f('b', 2), 2)->cast(Nothing()));
 }