Exemplo n.º 1
0
 public function testBind()
 {
     $m = 'abc';
     $f = function ($a) {
         return $a . ',';
     };
     $m1 = bind($m, $f);
     $this->assertEquals('a,b,c,', $m1);
 }
Exemplo n.º 2
0
 public function testBind()
 {
     $m = Just(3);
     $f = function ($a) {
         return Just($a + 2);
     };
     $m1 = bind($m, $f);
     $this->assertEquals(new Func\Maybe\Just(5), $m1);
     $m2 = $m->bind($f);
     $this->assertEquals(Just(5), $m2);
     $m3 = $m->bind(function ($_) {
         return Nothing();
     });
     $this->assertEquals(Nothing(), $m3);
 }
Exemplo n.º 3
0
 public function testForeach()
 {
     $m = [1, 2, 3];
     $i = 1;
     $mm = [$m];
     $x2 = function ($a) {
         return [$a * 2];
     };
     $mm2 = [bind($m, $x2)];
     $mm = mplus($mm, $mm2);
     $i = 1;
     $j = 1;
     foreach ($mm as $vv) {
         $i = $j;
         foreach ($vv as $v) {
             $this->assertEquals($i, $v);
             $i += $j;
         }
         $j++;
     }
     $this->assertEquals(8, $i);
     $this->assertEquals(3, $j);
 }