Skip to content

Commit

Permalink
add types to OppositeMonoid and OppositeSemigroup
Browse files Browse the repository at this point in the history
needed to conform with interface
  • Loading branch information
marcosh committed Aug 29, 2024
1 parent 2d6a02c commit b71e4b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
21 changes: 21 additions & 0 deletions spec/OppositeMonoidSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use Marcosh\LamPHPda\Instances\LinkedList\LinkedListMonoid;
use Marcosh\LamPHPda\Instances\OppositeMonoid;
use Marcosh\LamPHPda\Instances\OppositeSemigroup;
use Marcosh\LamPHPda\LinkedList;

describe('ListTOppositeMonoid', function () {
it('has the same empty element', function () {
expect((new OppositeMonoid(new LinkedListMonoid()))->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])));
});
});
4 changes: 2 additions & 2 deletions src/Instances/OppositeMonoid.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(private readonly Monoid $monoid)
/**
* @return A
*/
public function mempty()
public function mempty(): mixed
{
return $this->monoid->mempty();
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Instances/OppositeSemigroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b71e4b6

Please sign in to comment.