diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index ed3807f..2f929af 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -12,5 +12,6 @@ 'phpdoc_align' => ['align' => 'left'], 'phpdoc_to_comment' => false, 'concat_space' => ['spacing' => 'one'], - 'static_lambda' => true + 'static_lambda' => true, + 'single_line_empty_body' => false ])->setFinder($finder); diff --git a/CHANGELOG.md b/CHANGELOG.md index 34039c5..7a7304c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic versioning](http://semver.org/). +## [1.4.0] - 2023-09-27 + +- introduce `OppositeSemigroup` and `OppositMonoid` +- do not flip arguments on `ListL/ConcatenationMonoid` + ## [1.3.0] - 2023-08-23 - introduce `Alt` and `Plus` typeclasses diff --git a/bin/php-cs-fixer b/bin/php-cs-fixer index c587315..d4d7eab 100755 --- a/bin/php-cs-fixer +++ b/bin/php-cs-fixer @@ -1,3 +1,3 @@ #!/usr/bin/env bash -docker run --rm -v $(pwd):/app -w=/app php:8.1.0 vendor/bin/php-cs-fixer fix src --allow-risky=yes --format=checkstyle "$@" +docker run --rm -v $(pwd):/app -w=/app php:8.1.0 vendor/bin/php-cs-fixer fix src -vvv --allow-risky=yes --format=checkstyle "$@" diff --git a/src/Instances/ListL/ConcatenationMonoid.php b/src/Instances/ListL/ConcatenationMonoid.php index 6122282..8187c53 100644 --- a/src/Instances/ListL/ConcatenationMonoid.php +++ b/src/Instances/ListL/ConcatenationMonoid.php @@ -29,6 +29,6 @@ public function mempty(): array */ public function append($a, $b) { - return array_merge($b, $a); + return array_merge($a, $b); } } diff --git a/src/Instances/OppositeMonoid.php b/src/Instances/OppositeMonoid.php new file mode 100644 index 0000000..d2e924f --- /dev/null +++ b/src/Instances/OppositeMonoid.php @@ -0,0 +1,46 @@ + + * + * @psalm-immutable + */ +final class OppositeMonoid implements Monoid +{ + /** @var Monoid */ + private Monoid $monoid; + + /** + * @param Monoid $monoid + */ + public function __construct(Monoid $monoid) + { + $this->monoid = $monoid; + } + + /** + * @return A + */ + public function mempty() + { + return $this->monoid->mempty(); + } + + /** + * @param A $a + * @param A $b + * @return A + */ + public function append($a, $b) + { + return (new OppositeSemigroup($this->monoid))->append($a, $b); + } +} diff --git a/src/Instances/OppositeSemigroup.php b/src/Instances/OppositeSemigroup.php new file mode 100644 index 0000000..e35499c --- /dev/null +++ b/src/Instances/OppositeSemigroup.php @@ -0,0 +1,38 @@ + + * + * @psalm-immutable + */ +final class OppositeSemigroup implements Semigroup +{ + /** @var Semigroup */ + private Semigroup $semigroup; + + /** + * @param Semigroup $semigroup + */ + public function __construct(Semigroup $semigroup) + { + $this->semigroup = $semigroup; + } + + /** + * @param A $a + * @param A $b + * @return A + */ + public function append($a, $b) + { + return $this->semigroup->append($b, $a); + } +}