示例#1
0
 public function testTell()
 {
     $writer = Writer::of(2, Monoid::empty());
     list($xs, $log) = $writer->chain(function ($x) use($writer) {
         $log = new Monoid(['Hello, world!']);
         return $writer->tell($log)->map(function ($_) use($x) {
             return $x * 2;
         });
     })->run();
     $this->assertEquals($xs, 4, 'Maps correctly.');
     $this->assertEquals($log->value, ['Hello, world!'], 'Logs correctly.');
 }
示例#2
0
 public function testApplicativeConstructor()
 {
     $this->assertEquals(Writer::of(2, Monoid::empty())->run()[0], 2, 'Constructs an applicative.');
 }