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)); }
public function testMonoid() { $ret = ret('ab')->mappend(ret('cd')); $this->assertInstanceOf('Laiz\\Func\\Any', $ret); $this->assertEquals('abcd', $ret->cast('')); $this->assertEquals(['ab', 'cd'], $ret->cast([])); $this->assertEquals(Just('abcd'), $ret->cast(Nothing())); $this->assertEquals(['ab', 'cd', 'x'], $ret->mappend(['x'])); $this->assertEquals(Just('abcdx'), $ret->mappend(Just('x'))); $e = mempty(); $s = 'str'; $a = ['arr']; $m = Just('m'); $this->assertEquals('str', mappend($e, $s)); $this->assertEquals('str', mappend(mappend($e, $s), $e)); $this->assertEquals(['arr'], mappend($e, $a)); $this->assertEquals(['arr'], mappend(mappend($e, $a), $e)); $this->assertEquals(Just('m'), mappend($e, $m)); $this->assertEquals(Just('m'), mappend(mappend($e, $m), $e)); }
public static function ret($a) { return new Instance($a, mempty()); }