diff --git a/spec/OppositeMonoidSpec.php b/spec/OppositeMonoidSpec.php new file mode 100644 index 0000000..da3ef74 --- /dev/null +++ b/spec/OppositeMonoidSpec.php @@ -0,0 +1,21 @@ +mempty())->toEqual((new LinkedListMonoid())->mempty()); + }); +}); + +describe('ListTOppositeSemigroup', function () { + it('reverses the result of append', function () { + expect((new OppositeSemigroup(new LinkedListMonoid()))->append(LinkedList::fromList([1]), LinkedList::fromList([2]))) + ->toEqual((new LinkedListMonoid())->append(LinkedList::fromList([2]), LinkedList::fromList([1]))); + }); +}); \ No newline at end of file diff --git a/src/Instances/OppositeMonoid.php b/src/Instances/OppositeMonoid.php index b4d9a64..16f1922 100644 --- a/src/Instances/OppositeMonoid.php +++ b/src/Instances/OppositeMonoid.php @@ -25,7 +25,7 @@ public function __construct(private readonly Monoid $monoid) /** * @return A */ - public function mempty() + public function mempty(): mixed { return $this->monoid->mempty(); } @@ -35,7 +35,7 @@ public function mempty() * @param A $b * @return A */ - public function append($a, $b) + public function append($a, $b): mixed { return (new OppositeSemigroup($this->monoid))->append($a, $b); } diff --git a/src/Instances/OppositeSemigroup.php b/src/Instances/OppositeSemigroup.php index 7fc324a..56e5080 100644 --- a/src/Instances/OppositeSemigroup.php +++ b/src/Instances/OppositeSemigroup.php @@ -27,7 +27,7 @@ public function __construct(private readonly Semigroup $semigroup) * @param A $b * @return A */ - public function append($a, $b) + public function append($a, $b): mixed { return $this->semigroup->append($b, $a); }