From 5b3e5ff5cb696aec91c5aaa115c0628e03ab4e31 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Sat, 18 Mar 2023 22:49:13 +0100 Subject: [PATCH] chore: update codebase to PHP 8.1 --- docs/typeclasses/Applicative.md | 4 +- docs/typeclasses/Bifunctor.md | 4 +- docs/typeclasses/Functor.md | 4 +- docs/typeclasses/Monad.md | 4 +- docs/typeclasses/Profunctor.md | 4 +- docs/typeclasses/Traversable.md | 2 +- src/Either.php | 57 ++++++-------- src/IO.php | 6 +- src/Identity.php | 20 ++--- src/Instances/Either/EitherAlternative.php | 8 +- src/Instances/Either/EitherApplicative.php | 2 +- src/Instances/Either/EitherApply.php | 8 +- src/Instances/Either/EitherBifunctor.php | 4 +- src/Instances/Either/EitherFoldable.php | 6 +- src/Instances/Either/EitherFunctor.php | 4 +- src/Instances/Either/EitherMonad.php | 6 +- src/Instances/Either/EitherMonadThrow.php | 2 +- src/Instances/Either/EitherTraversable.php | 6 +- src/Instances/Either/JoinEitherSemigroup.php | 22 ++---- src/Instances/Either/MeetEitherSemigroup.php | 22 ++---- .../Either/ValidationApplicative.php | 8 +- src/Instances/Either/ValidationApply.php | 18 ++--- src/Instances/FirstSemigroup.php | 2 +- src/Instances/IO/IOApplicative.php | 4 +- src/Instances/IO/IOApply.php | 2 +- src/Instances/IO/IOFunctor.php | 2 +- src/Instances/IO/IOMonad.php | 4 +- .../Identity/IdentityApplicative.php | 2 +- src/Instances/Identity/IdentityFoldable.php | 2 +- src/Instances/Identity/IdentityMonad.php | 2 +- .../Identity/IdentityTraversable.php | 2 +- .../LinkedList/LinkedListApplicative.php | 2 +- src/Instances/LinkedList/LinkedListApply.php | 2 +- .../LinkedList/LinkedListFoldable.php | 2 +- .../LinkedList/LinkedListFunctor.php | 2 +- src/Instances/LinkedList/LinkedListMonad.php | 4 +- src/Instances/LinkedList/LinkedListMonoid.php | 2 +- .../LinkedList/LinkedListTraversable.php | 4 +- src/Instances/ListL/ConcatenationMonoid.php | 2 +- src/Instances/ListL/ListFoldable.php | 2 +- src/Instances/ListL/ListTraversable.php | 6 +- src/Instances/Maybe/MaybeApplicative.php | 2 +- src/Instances/Maybe/MaybeApply.php | 4 +- src/Instances/Maybe/MaybeFoldable.php | 4 +- src/Instances/Maybe/MaybeFunctor.php | 2 +- src/Instances/Maybe/MaybeMonad.php | 4 +- src/Instances/Maybe/MaybeMonadThrow.php | 2 +- src/Instances/Maybe/MaybeTraversable.php | 4 +- src/Instances/Pair/PairApplicative.php | 8 +- src/Instances/Pair/PairApply.php | 10 +-- src/Instances/Pair/PairBifunctor.php | 2 +- src/Instances/Pair/PairFunctor.php | 2 +- src/Instances/Pair/PairMonad.php | 12 +-- src/Instances/Reader/ReaderApplicative.php | 4 +- src/Instances/Reader/ReaderApply.php | 2 +- src/Instances/Reader/ReaderFunctor.php | 2 +- src/Instances/Reader/ReaderMonad.php | 4 +- src/Instances/State/StateApplicative.php | 4 +- src/Instances/State/StateApply.php | 6 +- src/Instances/State/StateFunctor.php | 2 +- src/Instances/State/StateMonad.php | 6 +- src/Instances/String/ConcatenationMonoid.php | 2 +- .../Traversable/TraversableFoldable.php | 2 +- .../Traversable/TraversableMonoid.php | 2 +- src/LinkedList.php | 31 +++----- src/ListL.php | 20 ++--- src/Maybe.php | 29 +++---- src/Pair.php | 26 +++---- src/Reader.php | 8 +- src/State.php | 10 +-- src/Traversable.php | 15 ++-- src/Typeclass/Applicative.php | 2 +- .../DefaultInstance/DefaultApplicative.php | 2 +- .../DefaultInstance/DefaultFoldable.php | 2 +- src/Typeclass/Extra/ExtraApply.php | 76 +++++++++---------- src/Typeclass/Extra/ExtraBifunctor.php | 8 +- src/Typeclass/Extra/ExtraMonad.php | 6 +- src/Typeclass/Extra/ExtraProfunctor.php | 6 +- src/Typeclass/Extra/ExtraTraversable.php | 6 +- src/Typeclass/Foldable.php | 2 +- src/Typeclass/MonadThrow.php | 2 +- src/Typeclass/Monoid.php | 2 +- src/Typeclass/Semigroup.php | 2 +- 83 files changed, 254 insertions(+), 364 deletions(-) diff --git a/docs/typeclasses/Applicative.md b/docs/typeclasses/Applicative.md index a9fec8c..03912b6 100644 --- a/docs/typeclasses/Applicative.md +++ b/docs/typeclasses/Applicative.md @@ -17,7 +17,7 @@ interface Applicative extends Apply * @param A $a * @return F */ - public function pure($a); + public function pure(mixed $a); } ``` @@ -34,7 +34,7 @@ The `Applicative` typeclass needs to satisfy four laws in addition to the `Apply ### Identity ```php -$applicative->apply($applicative->pure(fn($x) => $x), $y) == $y +$applicative->apply($applicative->pure(fn(mixed $x): mixed => $x), $y) == $y ``` ### Composition diff --git a/docs/typeclasses/Bifunctor.md b/docs/typeclasses/Bifunctor.md index b5e442b..8d56ab8 100644 --- a/docs/typeclasses/Bifunctor.md +++ b/docs/typeclasses/Bifunctor.md @@ -63,13 +63,13 @@ variables ### Identity ```php -$bifunctor->biMap(fn($x) => $x, fn($x) => $x, $a) == $a +$bifunctor->biMap(fn(mixed $x): mixed => $x, fn(mixed $x): mixed => $x, $a) == $a ``` ### Composition ```php -$bifunctor->biMap(fn($x) => $f($g($x)), fn($x) => $h($k($x)), $a) == $bifunctor->biMap(fn($x) => $f($x), fn($x) => $h($x), $bifunctor->biMap(fn($x) => $g($x), fn($x) => $k($x)), $a) +$bifunctor->biMap(fn(mixed $x): mixed => $f($g($x)), fn(mixed $x): mixed => $h($k($x)), $a) == $bifunctor->biMap(fn(mixed $x): mixed => $f($x), fn(mixed $x): mixed => $h($x), $bifunctor->biMap(fn(mixed $x): mixed => $g($x), fn(mixed $x): mixed => $k($x)), $a) ``` ## Implemented instances diff --git a/docs/typeclasses/Functor.md b/docs/typeclasses/Functor.md index ca6aeab..fe94b50 100644 --- a/docs/typeclasses/Functor.md +++ b/docs/typeclasses/Functor.md @@ -39,7 +39,7 @@ A `Functor` instance needs to abide by two laws: The identity function should be mapped to the identity function ```php -$functor->map(fn($x) => $x, $y) == $y +$functor->map(fn(mixed $x): mixed => $x, $y) == $y ``` ### Composition @@ -47,7 +47,7 @@ $functor->map(fn($x) => $x, $y) == $y Mapping the composition of two functions or composing the mapping of those functions should be the same thing ```php -$functor->map(fn($x) => $f($g($x)), $y) == $functor->map(fn($x) => $f($x), $functor->map(fn($x) => $g($x), $y)) +$functor->map(fn(mixed $x): mixed => $f($g($x)), $y) == $functor->map(fn(mixed $x): mixed => $f($x), $functor->map(fn(mixed $x): mixed => $g($x), $y)) ``` ## Implemented instances diff --git a/docs/typeclasses/Monad.md b/docs/typeclasses/Monad.md index acc0a26..50ad770 100644 --- a/docs/typeclasses/Monad.md +++ b/docs/typeclasses/Monad.md @@ -65,13 +65,13 @@ $monad->bind($monad->pure($a), $f) == $f($a) ### Right identity ```php -$monad->bind($a, fn($x) => $monad->pure($x)) == $a +$monad->bind($a, fn(mixed $x): mixed => $monad->pure($x)) == $a ``` ### Associativity ```php -$monad->bind($a, fn($x) => $monad->bind($f($x), $g)) == $monad->bind($monad->bind($a, $g), $g) +$monad->bind($a, fn(mixed $x): mixed => $monad->bind($f($x), $g)) == $monad->bind($monad->bind($a, $g), $g) ``` ## Implemented instances diff --git a/docs/typeclasses/Profunctor.md b/docs/typeclasses/Profunctor.md index 85b035d..43238bd 100644 --- a/docs/typeclasses/Profunctor.md +++ b/docs/typeclasses/Profunctor.md @@ -66,12 +66,12 @@ contravariant type variable. ### Identity ```php -$profunctor->diMap(fn($x) => $x, fn($x) => $x, $a) == $a +$profunctor->diMap(fn(mixed $x): mixed => $x, fn(mixed $x): mixed => $x, $a) == $a ``` ### Composition ```php -$profunctor->diMap(fn($x) => $f($g($x)), fn($x) => $h($k($x)), $a) == $profunctor->diMap(fn($x) => $g($x), fn($x) => $h($x), $profunctor->diMap(fn($x) => $f($x), fn($x) => $k($x)), $a) +$profunctor->diMap(fn(mixed $x): mixed => $f($g($x)), fn(mixed $x): mixed => $h($k($x)), $a) == $profunctor->diMap(fn(mixed $x): mixed => $g($x), fn(mixed $x): mixed => $h($x), $profunctor->diMap(fn(mixed $x): mixed => $f($x), fn(mixed $x): mixed => $k($x)), $a) ``` diff --git a/docs/typeclasses/Traversable.md b/docs/typeclasses/Traversable.md index ce1e653..6de5b28 100644 --- a/docs/typeclasses/Traversable.md +++ b/docs/typeclasses/Traversable.md @@ -54,7 +54,7 @@ $t($traversable->traverse($applicative, $f, $x)) == $traversable->traverse($appl ### Identity ```php -$traversable->traverse(new IdentityApplicative(), fn($x) => new Identity($x), $y) == new Identity($y) +$traversable->traverse(new IdentityApplicative(), fn(mixed $x): mixed => new Identity($x), $y) == new Identity($y) ``` ### Composition diff --git a/src/Either.php b/src/Either.php index 92e3cd7..26f8781 100644 --- a/src/Either.php +++ b/src/Either.php @@ -25,7 +25,6 @@ use Marcosh\LamPHPda\Typeclass\Functor; use Marcosh\LamPHPda\Typeclass\Monad; use Marcosh\LamPHPda\Typeclass\Traversable; -use Throwable; /** * @see https://github.com/marcosh/lamphpda/tree/master/docs/data-structures/Either.md @@ -41,25 +40,17 @@ */ final class Either implements DefaultMonad, DefaultTraversable, HK2Covariant { - private bool $isRight; - - /** @var null|A */ - private $leftValue; - - /** @var null|B */ - private $rightValue; - /** * @param null|A $leftValue * @param null|B $rightValue * * @psalm-mutation-free */ - private function __construct(bool $isRight, $leftValue = null, $rightValue = null) - { - $this->isRight = $isRight; - $this->leftValue = $leftValue; - $this->rightValue = $rightValue; + private function __construct( + private readonly bool $isRight, + private mixed $leftValue = null, + private mixed $rightValue = null + ) { } /** @@ -70,7 +61,7 @@ private function __construct(bool $isRight, $leftValue = null, $rightValue = nul * * @psalm-pure */ - public static function left($value): self + public static function left(mixed $value): self { return new self(false, $value); } @@ -83,7 +74,7 @@ public static function left($value): self * * @psalm-pure */ - public static function right($value): self + public static function right(mixed $value): self { return new self(true, null, $value); } @@ -147,19 +138,19 @@ public function eval( * @param A $a * @return A */ - public function fromLeft($a) + public function fromLeft(mixed $a): mixed { return $this->eval( /** * @param A $aa * @return A */ - static fn ($aa) => $aa, + static fn (mixed $aa): mixed => $aa, /** * @param B $_ * @return A */ - static fn ($_) => $a + static fn (mixed $_): mixed => $a ); } @@ -167,42 +158,42 @@ public function fromLeft($a) * @param B $b * @return B */ - public function fromRight($b) + public function fromRight(mixed $b): mixed { return $this->eval( /** * @param A $_ * @return B */ - static fn ($_) => $b, + static fn (mixed $_): mixed => $b, /** * @param B $bb * @return B */ - static fn ($bb) => $bb + static fn (mixed $bb): mixed => $bb ); } /** - * @throws Throwable * @return B + * @throws \Throwable */ - public function fromRightThrow(Throwable $e) + public function fromRightThrow(\Throwable $e): mixed { return $this->eval( /** * @param A $_ - * @throws Throwable * @return B + * @throws \Throwable */ - static function ($_) use ($e) { + static function (mixed $_) use ($e): never { throw $e; }, /** * @param B $b * @return B */ - static fn ($b) => $b + static fn (mixed $b): mixed => $b ); } @@ -213,7 +204,7 @@ public function toMaybe(): Maybe { return $this->eval( static fn (): Maybe => Maybe::nothing(), - static fn ($b): Maybe => Maybe::just($b) + static fn (mixed $b): Maybe => Maybe::just($b) ); } @@ -289,7 +280,7 @@ public function mapLeft(callable $f): self * @param B $b * @return B */ - static fn ($b) => $b + static fn (mixed $b): mixed => $b ); } @@ -330,7 +321,7 @@ public function apply(HK1 $f): self * * @psalm-pure */ - public static function ipure(Applicative $applicative, $a): self + public static function ipure(Applicative $applicative, mixed $a): self { return self::fromBrand($applicative->pure($a)); } @@ -345,7 +336,7 @@ public static function ipure(Applicative $applicative, $a): self * * @psalm-suppress LessSpecificImplementedReturnType */ - public static function pure($a): self + public static function pure(mixed $a): self { return self::ipure(new EitherApplicative(), $a); } @@ -387,7 +378,7 @@ public function bind(callable $f): self * * @psalm-mutation-free */ - public function ifoldr(Foldable $foldable, callable $f, $b) + public function ifoldr(Foldable $foldable, callable $f, mixed $b): mixed { /** @psalm-suppress ArgumentTypeCoercion */ return $foldable->foldr($f, $b, $this); @@ -401,7 +392,7 @@ public function ifoldr(Foldable $foldable, callable $f, $b) * * @psalm-mutation-free */ - public function foldr(callable $f, $b) + public function foldr(callable $f, mixed $b): mixed { return $this->ifoldr(new EitherFoldable(), $f, $b); } diff --git a/src/IO.php b/src/IO.php index e2ae4b6..e89e59b 100644 --- a/src/IO.php +++ b/src/IO.php @@ -66,7 +66,7 @@ public static function fromBrand(HK1 $hk): self /** * @return A */ - public function eval() + public function eval(): mixed { /** @psalm-suppress ImpureFunctionCall */ return ($this->action)(); @@ -122,7 +122,7 @@ public function apply(HK1 $f): self * * @psalm-pure */ - public static function ipure(Applicative $applicative, $a): self + public static function ipure(Applicative $applicative, mixed $a): self { return self::fromBrand($applicative->pure($a)); } @@ -134,7 +134,7 @@ public static function ipure(Applicative $applicative, $a): self * * @psalm-pure */ - public static function pure($a): self + public static function pure(mixed $a): self { return self::ipure(new IOApplicative(), $a); } diff --git a/src/Identity.php b/src/Identity.php index 05ca1a2..732d2a5 100644 --- a/src/Identity.php +++ b/src/Identity.php @@ -34,17 +34,11 @@ */ final class Identity implements DefaultMonad, DefaultTraversable { - /** - * @var A - */ - private $value; - /** * @param A $value */ - private function __construct($value) + private function __construct(private readonly mixed $value) { - $this->value = $value; } /** @@ -54,7 +48,7 @@ private function __construct($value) * * @psalm-pure */ - public static function wrap($value): self + public static function wrap(mixed $value): self { return new self($value); } @@ -75,7 +69,7 @@ public static function fromBrand(HK1 $b): self /** * @return A */ - public function unwrap() + public function unwrap(): mixed { return $this->value; } @@ -138,7 +132,7 @@ public function apply(HK1 $f): self * * @psalm-pure */ - public static function ipure(Applicative $applicative, $a): self + public static function ipure(Applicative $applicative, mixed $a): self { return self::fromBrand($applicative->pure($a)); } @@ -152,7 +146,7 @@ public static function ipure(Applicative $applicative, $a): self * * @psalm-suppress LessSpecificImplementedReturnType */ - public static function pure($a): self + public static function pure(mixed $a): self { return self::ipure(new IdentityApplicative(), $a); } @@ -191,7 +185,7 @@ public function bind(callable $f): self * * @psalm-suppress ArgumentTypeCoercion */ - public function ifoldr(Foldable $foldable, callable $f, $b) + public function ifoldr(Foldable $foldable, callable $f, mixed $b): mixed { return $foldable->foldr($f, $b, $this); } @@ -202,7 +196,7 @@ public function ifoldr(Foldable $foldable, callable $f, $b) * @param B $b * @return B */ - public function foldr(callable $f, $b) + public function foldr(callable $f, mixed $b): mixed { return $this->ifoldr(new IdentityFoldable(), $f, $b); } diff --git a/src/Instances/Either/EitherAlternative.php b/src/Instances/Either/EitherAlternative.php index a3847d5..51c2809 100644 --- a/src/Instances/Either/EitherAlternative.php +++ b/src/Instances/Either/EitherAlternative.php @@ -20,15 +20,11 @@ */ final class EitherAlternative implements Alternative { - /** @var Monoid */ - private Monoid $eMonoid; - /** * @param Monoid $eMonoid */ - public function __construct(Monoid $eMonoid) + public function __construct(private readonly Monoid $eMonoid) { - $this->eMonoid = $eMonoid; } /** @@ -72,7 +68,7 @@ public function apply(HK1 $f, HK1 $a): Either * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Either + public function pure(mixed $a): Either { return (new EitherApplicative())->pure($a); } diff --git a/src/Instances/Either/EitherApplicative.php b/src/Instances/Either/EitherApplicative.php index 90a998b..21bc61c 100644 --- a/src/Instances/Either/EitherApplicative.php +++ b/src/Instances/Either/EitherApplicative.php @@ -59,7 +59,7 @@ public function apply(HK1 $f, HK1 $a): Either * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Either + public function pure(mixed $a): Either { return Either::right($a); } diff --git a/src/Instances/Either/EitherApply.php b/src/Instances/Either/EitherApply.php index b018420..5545ee6 100644 --- a/src/Instances/Either/EitherApply.php +++ b/src/Instances/Either/EitherApply.php @@ -55,22 +55,22 @@ public function apply(HK1 $f, HK1 $a): Either * @param C $c * @return Either */ - static fn ($c): Either => Either::left($c), + static fn (mixed $c): Either => Either::left($c), /** * @param callable(A): B $f * @return Either */ - static fn ($f): Either => $eitherA->eval( + static fn (mixed $f): Either => $eitherA->eval( /** * @param C $c * @return Either */ - static fn ($c): Either => Either::left($c), + static fn (mixed $c): Either => Either::left($c), /** * @param A $a * @return Either */ - static fn ($a): Either => Either::right($f($a)) + static fn (mixed $a): Either => Either::right($f($a)) ) ); } diff --git a/src/Instances/Either/EitherBifunctor.php b/src/Instances/Either/EitherBifunctor.php index 70a5bfe..27f7e33 100644 --- a/src/Instances/Either/EitherBifunctor.php +++ b/src/Instances/Either/EitherBifunctor.php @@ -33,12 +33,12 @@ public function biMap(callable $f, callable $g, HK2Covariant $a): Either * @param A $a * @return Either */ - static fn ($a): Either => Either::left($f($a)), + static fn (mixed $a): Either => Either::left($f($a)), /** * @param B $b * @return Either */ - static fn ($b): Either => Either::right($g($b)) + static fn (mixed $b): Either => Either::right($g($b)) ); } } diff --git a/src/Instances/Either/EitherFoldable.php b/src/Instances/Either/EitherFoldable.php index f96e27a..8f68f71 100644 --- a/src/Instances/Either/EitherFoldable.php +++ b/src/Instances/Either/EitherFoldable.php @@ -28,7 +28,7 @@ final class EitherFoldable implements Foldable * * @psalm-pure */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { $eitherA = Either::fromBrand($a); @@ -37,12 +37,12 @@ public function foldr(callable $f, $b, HK1 $a) * @param C $_ * @return B */ - static fn ($_) => $b, + static fn (mixed $_): mixed => $b, /** * @param A $a * @return B */ - static fn ($a) => $f($a, $b) + static fn (mixed $a): mixed => $f($a, $b) ); } } diff --git a/src/Instances/Either/EitherFunctor.php b/src/Instances/Either/EitherFunctor.php index fe32728..35d4c63 100644 --- a/src/Instances/Either/EitherFunctor.php +++ b/src/Instances/Either/EitherFunctor.php @@ -36,12 +36,12 @@ public function map(callable $f, HK1 $a): Either * @param C $b * @return Either */ - static fn ($b): Either => Either::left($b), + static fn (mixed $b): Either => Either::left($b), /** * @param A $b * @return Either */ - static fn ($b): Either => Either::right($f($b)) + static fn (mixed $b): Either => Either::right($f($b)) ); } } diff --git a/src/Instances/Either/EitherMonad.php b/src/Instances/Either/EitherMonad.php index 97bea1f..6c5ffa1 100644 --- a/src/Instances/Either/EitherMonad.php +++ b/src/Instances/Either/EitherMonad.php @@ -60,7 +60,7 @@ public function apply(HK1 $f, HK1 $a): Either * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Either + public function pure(mixed $a): Either { return (new EitherApplicative())->pure($a); } @@ -85,12 +85,12 @@ public function bind(HK1 $a, callable $f): Either * @param C $c * @return Either */ - static fn ($c) => Either::left($c), + static fn (mixed $c): Either => Either::left($c), /** * @param A $b * @return Either */ - static fn ($b) => Either::fromBrand($f($b)) + static fn (mixed $b): Either => Either::fromBrand($f($b)) ); } } diff --git a/src/Instances/Either/EitherMonadThrow.php b/src/Instances/Either/EitherMonadThrow.php index 991372e..d6c165b 100644 --- a/src/Instances/Either/EitherMonadThrow.php +++ b/src/Instances/Either/EitherMonadThrow.php @@ -62,7 +62,7 @@ public function apply(HK1 $f, HK1 $a): Either * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Either + public function pure(mixed $a): Either { return (new EitherApplicative())->pure($a); } diff --git a/src/Instances/Either/EitherTraversable.php b/src/Instances/Either/EitherTraversable.php index 5da9025..5aa894e 100644 --- a/src/Instances/Either/EitherTraversable.php +++ b/src/Instances/Either/EitherTraversable.php @@ -46,7 +46,7 @@ public function map(callable $f, HK1 $a): HK1 * * @psalm-pure */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { return (new EitherFoldable())->foldr($f, $b, $a); } @@ -74,7 +74,7 @@ public function traverse(Applicative $applicative, callable $f, HK1 $a): HK1 * @param C $c * @return HK1> */ - static function ($c) use ($applicative): HK1 { + static function (mixed $c) use ($applicative): HK1 { /** @var Either $eitherCB */ $eitherCB = Either::left($c); @@ -84,7 +84,7 @@ static function ($c) use ($applicative): HK1 { * @param A $a * @return HK1> */ - static fn ($a): HK1 => $applicative->map($right, $f($a)) + static fn (mixed $a): HK1 => $applicative->map($right, $f($a)) ); } } diff --git a/src/Instances/Either/JoinEitherSemigroup.php b/src/Instances/Either/JoinEitherSemigroup.php index 3fc3a20..68bf924 100644 --- a/src/Instances/Either/JoinEitherSemigroup.php +++ b/src/Instances/Either/JoinEitherSemigroup.php @@ -21,20 +21,12 @@ */ final class JoinEitherSemigroup implements Semigroup { - /** @var Semigroup */ - private Semigroup $eSemigroup; - - /** @var Semigroup */ - private Semigroup $bSemigroup; - /** * @param Semigroup $eSemigroup * @param Semigroup $bSemigroup */ - public function __construct(Semigroup $eSemigroup, Semigroup $bSemigroup) + public function __construct(private readonly Semigroup $eSemigroup, private readonly Semigroup $bSemigroup) { - $this->eSemigroup = $eSemigroup; - $this->bSemigroup = $bSemigroup; } /** @@ -51,33 +43,33 @@ public function append($a, $b): Either * @param E $ea * @return Either */ - fn ($ea): Either => $b->eval( + fn (mixed $ea): Either => $b->eval( /** * @param E $eb * @return Either */ - fn ($eb): Either => Either::left($this->eSemigroup->append($ea, $eb)), + fn (mixed $eb): Either => Either::left($this->eSemigroup->append($ea, $eb)), /** * @param B $_ * @return Either */ - static fn ($_): Either => Either::left($ea) + static fn (mixed $_): Either => Either::left($ea) ), /** * @param B $va * @return Either */ - fn ($va): Either => $b->eval( + fn (mixed $va): Either => $b->eval( /** * @param E $eb * @return Either */ - static fn ($eb): Either => Either::left($eb), + static fn (mixed $eb): Either => Either::left($eb), /** * @param B $vb * @return Either */ - fn ($vb): Either => Either::right($this->bSemigroup->append($va, $vb)) + fn (mixed $vb): Either => Either::right($this->bSemigroup->append($va, $vb)) ) ); } diff --git a/src/Instances/Either/MeetEitherSemigroup.php b/src/Instances/Either/MeetEitherSemigroup.php index 2242a9d..33ad55d 100644 --- a/src/Instances/Either/MeetEitherSemigroup.php +++ b/src/Instances/Either/MeetEitherSemigroup.php @@ -21,20 +21,12 @@ */ final class MeetEitherSemigroup implements Semigroup { - /** @var Semigroup */ - private Semigroup $eSemigroup; - - /** @var Semigroup */ - private Semigroup $bSemigroup; - /** * @param Semigroup $eSemigroup * @param Semigroup $bSemigroup */ - public function __construct(Semigroup $eSemigroup, Semigroup $bSemigroup) + public function __construct(private readonly Semigroup $eSemigroup, private readonly Semigroup $bSemigroup) { - $this->eSemigroup = $eSemigroup; - $this->bSemigroup = $bSemigroup; } /** @@ -51,33 +43,33 @@ public function append($a, $b): Either * @param E $ea * @return Either */ - fn ($ea): Either => $b->eval( + fn (mixed $ea): Either => $b->eval( /** * @param E $eb * @return Either */ - fn ($eb): Either => Either::left($this->eSemigroup->append($ea, $eb)), + fn (mixed $eb): Either => Either::left($this->eSemigroup->append($ea, $eb)), /** * @param B $vb * @return Either */ - static fn ($vb): Either => Either::right($vb) + static fn (mixed $vb): Either => Either::right($vb) ), /** * @param B $va * @return Either */ - fn ($va): Either => $b->eval( + fn (mixed $va): Either => $b->eval( /** * @param E $_ * @return Either */ - static fn ($_): Either => Either::right($va), + static fn (mixed $_): Either => Either::right($va), /** * @param B $vb * @return Either */ - fn ($vb): Either => Either::right($this->bSemigroup->append($va, $vb)) + fn (mixed $vb): Either => Either::right($this->bSemigroup->append($va, $vb)) ) ); } diff --git a/src/Instances/Either/ValidationApplicative.php b/src/Instances/Either/ValidationApplicative.php index 5a1bc0e..6ab62e7 100644 --- a/src/Instances/Either/ValidationApplicative.php +++ b/src/Instances/Either/ValidationApplicative.php @@ -19,15 +19,11 @@ */ final class ValidationApplicative implements Applicative { - /** @var Semigroup */ - private Semigroup $semigroup; - /** * @param Semigroup $semigroup */ - public function __construct(Semigroup $semigroup) + public function __construct(private readonly Semigroup $semigroup) { - $this->semigroup = $semigroup; } /** @@ -72,7 +68,7 @@ public function apply(HK1 $f, HK1 $a): HK1 * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Either + public function pure(mixed $a): Either { return Either::right($a); } diff --git a/src/Instances/Either/ValidationApply.php b/src/Instances/Either/ValidationApply.php index b74598c..00b2df0 100644 --- a/src/Instances/Either/ValidationApply.php +++ b/src/Instances/Either/ValidationApply.php @@ -19,15 +19,11 @@ */ final class ValidationApply implements Apply { - /** @var Semigroup */ - private Semigroup $semigroup; - /** * @param Semigroup $semigroup */ - public function __construct(Semigroup $semigroup) + public function __construct(private readonly Semigroup $semigroup) { - $this->semigroup = $semigroup; } /** @@ -67,33 +63,33 @@ public function apply(HK1 $f, HK1 $a): HK1 * @param E $ef * @return Either */ - fn ($ef): Either => $eitherA->eval( + fn (mixed $ef): Either => $eitherA->eval( /** * @param E $ea * @return Either */ - fn ($ea): Either => Either::left($this->semigroup->append($ef, $ea)), + fn (mixed $ea): Either => Either::left($this->semigroup->append($ef, $ea)), /** * @param A $_a * @return Either */ - static fn ($_a): Either => Either::left($ef) + static fn (mixed $_a): Either => Either::left($ef) ), /** * @param callable(A): B $f * @return Either */ - static fn ($f): Either => $eitherA->eval( + static fn (mixed $f): Either => $eitherA->eval( /** * @param E $e * @return Either */ - static fn ($e): Either => Either::left($e), + static fn (mixed $e): Either => Either::left($e), /** * @param A $a * @return Either */ - static fn ($a): Either => Either::right($f($a)) + static fn (mixed $a): Either => Either::right($f($a)) ) ); } diff --git a/src/Instances/FirstSemigroup.php b/src/Instances/FirstSemigroup.php index 403f403..59fee47 100644 --- a/src/Instances/FirstSemigroup.php +++ b/src/Instances/FirstSemigroup.php @@ -20,7 +20,7 @@ final class FirstSemigroup implements Semigroup * @param A $b * @return A */ - public function append($a, $b) + public function append(mixed $a, mixed $b): mixed { return $a; } diff --git a/src/Instances/IO/IOApplicative.php b/src/Instances/IO/IOApplicative.php index b59f864..b8fb0de 100644 --- a/src/Instances/IO/IOApplicative.php +++ b/src/Instances/IO/IOApplicative.php @@ -51,8 +51,8 @@ public function apply(HK1 $f, HK1 $a): IO * * @psalm-pure */ - public function pure($a): IO + public function pure(mixed $a): IO { - return IO::action(static fn () => $a); + return IO::action(static fn (): mixed => $a); } } diff --git a/src/Instances/IO/IOApply.php b/src/Instances/IO/IOApply.php index 3dc547d..eaa00f0 100644 --- a/src/Instances/IO/IOApply.php +++ b/src/Instances/IO/IOApply.php @@ -44,6 +44,6 @@ public function apply(HK1 $f, HK1 $a): IO $ioF = IO::fromBrand($f); $ioA = IO::fromBrand($a); - return IO::action(static fn () => $ioF->eval()($ioA->eval())); + return IO::action(static fn (): mixed => $ioF->eval()($ioA->eval())); } } diff --git a/src/Instances/IO/IOFunctor.php b/src/Instances/IO/IOFunctor.php index 0b000f8..4924156 100644 --- a/src/Instances/IO/IOFunctor.php +++ b/src/Instances/IO/IOFunctor.php @@ -27,6 +27,6 @@ final class IOFunctor implements Functor */ public function map(callable $f, HK1 $a): IO { - return IO::action(static fn () => $f(IO::fromBrand($a)->eval())); + return IO::action(static fn (): mixed => $f(IO::fromBrand($a)->eval())); } } diff --git a/src/Instances/IO/IOMonad.php b/src/Instances/IO/IOMonad.php index 42c9149..82ecb2e 100644 --- a/src/Instances/IO/IOMonad.php +++ b/src/Instances/IO/IOMonad.php @@ -51,7 +51,7 @@ public function apply(HK1 $f, HK1 $a): IO * * @psalm-pure */ - public function pure($a): IO + public function pure(mixed $a): IO { return (new IOApplicative())->pure($a); } @@ -69,6 +69,6 @@ public function bind(HK1 $a, callable $f): IO { $ioA = IO::fromBrand($a); - return IO::action(static fn () => IO::fromBrand($f($ioA->eval()))->eval()); + return IO::action(static fn (): mixed => IO::fromBrand($f($ioA->eval()))->eval()); } } diff --git a/src/Instances/Identity/IdentityApplicative.php b/src/Instances/Identity/IdentityApplicative.php index 5d02da2..09d8f68 100644 --- a/src/Instances/Identity/IdentityApplicative.php +++ b/src/Instances/Identity/IdentityApplicative.php @@ -57,7 +57,7 @@ public function apply(HK1 $f, HK1 $a): Identity * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Identity + public function pure(mixed $a): Identity { return Identity::wrap($a); } diff --git a/src/Instances/Identity/IdentityFoldable.php b/src/Instances/Identity/IdentityFoldable.php index ec47161..24a4b5e 100644 --- a/src/Instances/Identity/IdentityFoldable.php +++ b/src/Instances/Identity/IdentityFoldable.php @@ -24,7 +24,7 @@ final class IdentityFoldable implements Foldable * @param HK1 $a * @return B */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { $identityA = Identity::fromBrand($a); diff --git a/src/Instances/Identity/IdentityMonad.php b/src/Instances/Identity/IdentityMonad.php index c021497..ddd9443 100644 --- a/src/Instances/Identity/IdentityMonad.php +++ b/src/Instances/Identity/IdentityMonad.php @@ -57,7 +57,7 @@ public function apply(HK1 $f, HK1 $a): Identity * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Identity + public function pure(mixed $a): Identity { return (new IdentityApplicative())->pure($a); } diff --git a/src/Instances/Identity/IdentityTraversable.php b/src/Instances/Identity/IdentityTraversable.php index 30c838f..7fe50bf 100644 --- a/src/Instances/Identity/IdentityTraversable.php +++ b/src/Instances/Identity/IdentityTraversable.php @@ -42,7 +42,7 @@ public function map(callable $f, HK1 $a): Identity * @param HK1 $a * @return B */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { return (new IdentityFoldable())->foldr($f, $b, $a); } diff --git a/src/Instances/LinkedList/LinkedListApplicative.php b/src/Instances/LinkedList/LinkedListApplicative.php index f7dc0ec..5db361e 100644 --- a/src/Instances/LinkedList/LinkedListApplicative.php +++ b/src/Instances/LinkedList/LinkedListApplicative.php @@ -57,7 +57,7 @@ public function apply(HK1 $f, HK1 $a): LinkedList * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): LinkedList + public function pure(mixed $a): LinkedList { return LinkedList::cons($a, LinkedList::empty()); } diff --git a/src/Instances/LinkedList/LinkedListApply.php b/src/Instances/LinkedList/LinkedListApply.php index ea45c3d..315d336 100644 --- a/src/Instances/LinkedList/LinkedListApply.php +++ b/src/Instances/LinkedList/LinkedListApply.php @@ -53,7 +53,7 @@ public function apply(HK1 $f, HK1 $a): LinkedList * @param callable(A): B $ff * @param LinkedList $l */ - static fn (callable $ff, LinkedList $l) => $l->append($listA->map($ff)), + static fn (callable $ff, LinkedList $l): mixed => $l->append($listA->map($ff)), LinkedList::empty() ); } diff --git a/src/Instances/LinkedList/LinkedListFoldable.php b/src/Instances/LinkedList/LinkedListFoldable.php index 95cddf8..5f9aaf2 100644 --- a/src/Instances/LinkedList/LinkedListFoldable.php +++ b/src/Instances/LinkedList/LinkedListFoldable.php @@ -24,7 +24,7 @@ final class LinkedListFoldable implements Foldable * @param HK1 $a * @return B */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { $listA = LinkedList::fromBrand($a); diff --git a/src/Instances/LinkedList/LinkedListFunctor.php b/src/Instances/LinkedList/LinkedListFunctor.php index 6a2d908..89695f7 100644 --- a/src/Instances/LinkedList/LinkedListFunctor.php +++ b/src/Instances/LinkedList/LinkedListFunctor.php @@ -37,7 +37,7 @@ public function map(callable $f, HK1 $a): LinkedList * @param LinkedList $l * @return LinkedList */ - static fn ($element, LinkedList $l) => LinkedList::cons($f($element), $l), + static fn (mixed $element, LinkedList $l): LinkedList => LinkedList::cons($f($element), $l), LinkedList::empty() ); } diff --git a/src/Instances/LinkedList/LinkedListMonad.php b/src/Instances/LinkedList/LinkedListMonad.php index 8e8ae9a..d624bb0 100644 --- a/src/Instances/LinkedList/LinkedListMonad.php +++ b/src/Instances/LinkedList/LinkedListMonad.php @@ -57,7 +57,7 @@ public function apply(HK1 $f, HK1 $a): LinkedList * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): LinkedList + public function pure(mixed $a): LinkedList { return (new LinkedListApplicative())->pure($a); } @@ -83,7 +83,7 @@ public function bind(HK1 $a, callable $f): LinkedList * @param LinkedList $l * @return LinkedList */ - static fn ($element, LinkedList $l) => $l->append(LinkedList::fromBrand($f($element))), + static fn (mixed $element, LinkedList $l): LinkedList => $l->append(LinkedList::fromBrand($f($element))), LinkedList::empty() ); } diff --git a/src/Instances/LinkedList/LinkedListMonoid.php b/src/Instances/LinkedList/LinkedListMonoid.php index 6148a14..6464da0 100644 --- a/src/Instances/LinkedList/LinkedListMonoid.php +++ b/src/Instances/LinkedList/LinkedListMonoid.php @@ -37,7 +37,7 @@ public function append($a, $b): LinkedList * @param LinkedList $list * @return LinkedList */ - static fn ($element, LinkedList $list) => LinkedList::cons($element, $list), + static fn (mixed $element, LinkedList $list): LinkedList => LinkedList::cons($element, $list), $a ); } diff --git a/src/Instances/LinkedList/LinkedListTraversable.php b/src/Instances/LinkedList/LinkedListTraversable.php index c07b159..3f34d2b 100644 --- a/src/Instances/LinkedList/LinkedListTraversable.php +++ b/src/Instances/LinkedList/LinkedListTraversable.php @@ -47,7 +47,7 @@ public function map(callable $f, HK1 $a): LinkedList * * @psalm-suppress LessSpecificImplementedReturnType */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { return (new LinkedListFoldable())->foldr($f, $b, $a); } @@ -75,7 +75,7 @@ public function traverse(Applicative $applicative, callable $f, HK1 $a): HK1 * @param HK1> $acc * @return HK1> */ - static fn ($element, HK1 $acc) => (new ExtraApply($applicative))->lift2( + static fn (mixed $element, HK1 $acc): mixed => (new ExtraApply($applicative))->lift2( [LinkedList::class, 'cons'], $f($element), $acc diff --git a/src/Instances/ListL/ConcatenationMonoid.php b/src/Instances/ListL/ConcatenationMonoid.php index 6122282..22d2df6 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 [...$b, ...$a]; } } diff --git a/src/Instances/ListL/ListFoldable.php b/src/Instances/ListL/ListFoldable.php index 1af09dc..8068b57 100644 --- a/src/Instances/ListL/ListFoldable.php +++ b/src/Instances/ListL/ListFoldable.php @@ -26,7 +26,7 @@ final class ListFoldable implements Foldable * * @psalm-pure */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { $aList = ListL::fromBrand($a); diff --git a/src/Instances/ListL/ListTraversable.php b/src/Instances/ListL/ListTraversable.php index 5f6351f..6d054fa 100644 --- a/src/Instances/ListL/ListTraversable.php +++ b/src/Instances/ListL/ListTraversable.php @@ -29,7 +29,7 @@ final class ListTraversable implements Traversable * * @psalm-pure */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { return (new ListFoldable())->foldr($f, $b, $a); } @@ -69,13 +69,13 @@ public function traverse(Applicative $applicative, callable $f, HK1 $a): HK1 * @param HK1> $d * @return HK1> */ - static fn ($c, $d): HK1 => (new ExtraApply($applicative))->lift2( + static fn (mixed $c, mixed $d): HK1 => (new ExtraApply($applicative))->lift2( /** * @param B $h * @param HK1 $t * @return HK1 */ - static fn ($h, $t): HK1 => ListL::fromBrand($t)->append($h), + static fn (mixed $h, mixed $t): HK1 => ListL::fromBrand($t)->append($h), $f($c), $d ), diff --git a/src/Instances/Maybe/MaybeApplicative.php b/src/Instances/Maybe/MaybeApplicative.php index 308a0b3..4697fc7 100644 --- a/src/Instances/Maybe/MaybeApplicative.php +++ b/src/Instances/Maybe/MaybeApplicative.php @@ -57,7 +57,7 @@ public function apply(HK1 $f, HK1 $a): Maybe * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Maybe + public function pure(mixed $a): Maybe { return Maybe::just($a); } diff --git a/src/Instances/Maybe/MaybeApply.php b/src/Instances/Maybe/MaybeApply.php index 1e5ae31..013b678 100644 --- a/src/Instances/Maybe/MaybeApply.php +++ b/src/Instances/Maybe/MaybeApply.php @@ -54,13 +54,13 @@ public function apply(HK1 $f, HK1 $a): Maybe * @param A $value * @return Maybe */ - static fn ($value): Maybe => $maybeF->eval( + static fn (mixed $value): Maybe => $maybeF->eval( Maybe::nothing(), /** * @psalm-param callable(A): B $g * @psalm-return Maybe */ - static fn ($g): Maybe => Maybe::just($g($value)) + static fn (mixed $g): Maybe => Maybe::just($g($value)) ) ); } diff --git a/src/Instances/Maybe/MaybeFoldable.php b/src/Instances/Maybe/MaybeFoldable.php index 9555e9a..34276eb 100644 --- a/src/Instances/Maybe/MaybeFoldable.php +++ b/src/Instances/Maybe/MaybeFoldable.php @@ -24,7 +24,7 @@ final class MaybeFoldable implements Foldable * @param HK1 $a * @return B */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { $maybeA = Maybe::fromBrand($a); @@ -34,7 +34,7 @@ public function foldr(callable $f, $b, HK1 $a) * @param A $a * @return B */ - static fn ($a) => $f($a, $b) + static fn (mixed $a): mixed => $f($a, $b) ); } } diff --git a/src/Instances/Maybe/MaybeFunctor.php b/src/Instances/Maybe/MaybeFunctor.php index 540d6aa..5f6e9fb 100644 --- a/src/Instances/Maybe/MaybeFunctor.php +++ b/src/Instances/Maybe/MaybeFunctor.php @@ -35,7 +35,7 @@ public function map(callable $f, HK1 $a): Maybe * @param A $value * @return Maybe */ - static fn ($value): Maybe => Maybe::just($f($value)) + static fn (mixed $value): Maybe => Maybe::just($f($value)) ); } } diff --git a/src/Instances/Maybe/MaybeMonad.php b/src/Instances/Maybe/MaybeMonad.php index 6dbf4a0..be8ea70 100644 --- a/src/Instances/Maybe/MaybeMonad.php +++ b/src/Instances/Maybe/MaybeMonad.php @@ -57,7 +57,7 @@ public function apply(HK1 $f, HK1 $a): Maybe * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Maybe + public function pure(mixed $a): Maybe { return (new MaybeApplicative())->pure($a); } @@ -83,7 +83,7 @@ public function bind(HK1 $a, callable $f): Maybe * @param A $a * @return Maybe */ - static fn ($a): Maybe => Maybe::fromBrand($f($a)) + static fn (mixed $a): Maybe => Maybe::fromBrand($f($a)) ); } } diff --git a/src/Instances/Maybe/MaybeMonadThrow.php b/src/Instances/Maybe/MaybeMonadThrow.php index 6fd8c2f..b0abab1 100644 --- a/src/Instances/Maybe/MaybeMonadThrow.php +++ b/src/Instances/Maybe/MaybeMonadThrow.php @@ -59,7 +59,7 @@ public function apply(HK1 $f, HK1 $a): Maybe * * @psalm-suppress LessSpecificImplementedReturnType */ - public function pure($a): Maybe + public function pure(mixed $a): Maybe { return (new MaybeApplicative())->pure($a); } diff --git a/src/Instances/Maybe/MaybeTraversable.php b/src/Instances/Maybe/MaybeTraversable.php index fa9d5c5..9003da6 100644 --- a/src/Instances/Maybe/MaybeTraversable.php +++ b/src/Instances/Maybe/MaybeTraversable.php @@ -44,7 +44,7 @@ public function map(callable $f, HK1 $a): Maybe * * @psalm-pure */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { return (new MaybeFoldable())->foldr($f, $b, $a); } @@ -76,7 +76,7 @@ public function traverse(Applicative $applicative, callable $f, HK1 $a): HK1 * @param A $a * @return HK1> */ - static fn ($a): HK1 => $applicative->map([Maybe::class, 'just'], $f($a)) + static fn (mixed $a): HK1 => $applicative->map([Maybe::class, 'just'], $f($a)) ); } } diff --git a/src/Instances/Pair/PairApplicative.php b/src/Instances/Pair/PairApplicative.php index bb249f8..b14cebf 100644 --- a/src/Instances/Pair/PairApplicative.php +++ b/src/Instances/Pair/PairApplicative.php @@ -19,15 +19,11 @@ */ final class PairApplicative implements Applicative { - /** @var Monoid */ - private Monoid $monoid; - /** * @param Monoid $monoid */ - public function __construct(Monoid $monoid) + public function __construct(private readonly Monoid $monoid) { - $this->monoid = $monoid; } /** @@ -67,7 +63,7 @@ public function apply(HK1 $f, HK1 $a): Pair * * @psalm-suppress ImplementedReturnTypeMismatch */ - public function pure($a): Pair + public function pure(mixed $a): Pair { return Pair::pair($this->monoid->mempty(), $a); } diff --git a/src/Instances/Pair/PairApply.php b/src/Instances/Pair/PairApply.php index 0640863..6dbd2a4 100644 --- a/src/Instances/Pair/PairApply.php +++ b/src/Instances/Pair/PairApply.php @@ -19,15 +19,11 @@ */ final class PairApply implements Apply { - /** @var Semigroup */ - private Semigroup $semigroup; - /** * @param Semigroup $semigroup */ - public function __construct(Semigroup $semigroup) + public function __construct(private readonly Semigroup $semigroup) { - $this->semigroup = $semigroup; } /** @@ -66,13 +62,13 @@ public function apply(HK1 $f, HK1 $a): Pair * @param callable(A): B $f * @return Pair */ - fn ($cf, callable $f) => $pairA->eval( + fn (mixed $cf, callable $f): Pair => $pairA->eval( /** * @param C $ca * @param A $a * @return Pair */ - fn ($ca, callable $a) => Pair::pair($this->semigroup->append($cf, $ca), $f($a)) + fn (mixed $ca, callable $a): Pair => Pair::pair($this->semigroup->append($cf, $ca), $f($a)) ) ); } diff --git a/src/Instances/Pair/PairBifunctor.php b/src/Instances/Pair/PairBifunctor.php index c9adb0a..2a0ad3f 100644 --- a/src/Instances/Pair/PairBifunctor.php +++ b/src/Instances/Pair/PairBifunctor.php @@ -36,7 +36,7 @@ public function biMap(callable $f, callable $g, HK2Covariant $a): HK2Covariant * @param B $right * @return Pair */ - static fn ($left, $right): Pair => Pair::pair($f($left), $g($right)) + static fn (mixed $left, mixed $right): Pair => Pair::pair($f($left), $g($right)) ); } } diff --git a/src/Instances/Pair/PairFunctor.php b/src/Instances/Pair/PairFunctor.php index dec0dd0..12a71dd 100644 --- a/src/Instances/Pair/PairFunctor.php +++ b/src/Instances/Pair/PairFunctor.php @@ -35,7 +35,7 @@ public function map(callable $f, HK1 $a): HK1 * @param A $b * @return Pair */ - static fn ($c, $b) => Pair::pair($c, $f($b)) + static fn (mixed $c, mixed $b): Pair => Pair::pair($c, $f($b)) ); } } diff --git a/src/Instances/Pair/PairMonad.php b/src/Instances/Pair/PairMonad.php index 8e0176e..b94fa85 100644 --- a/src/Instances/Pair/PairMonad.php +++ b/src/Instances/Pair/PairMonad.php @@ -19,15 +19,11 @@ */ final class PairMonad implements Monad { - /** @var Monoid */ - private Monoid $monoid; - /** * @param Monoid $monoid */ - public function __construct(Monoid $monoid) + public function __construct(private readonly Monoid $monoid) { - $this->monoid = $monoid; } /** @@ -67,7 +63,7 @@ public function apply(HK1 $f, HK1 $a): Pair * * @psalm-suppress ImplementedReturnTypeMismatch */ - public function pure($a): Pair + public function pure(mixed $a): Pair { return (new PairApplicative($this->monoid))->pure($a); } @@ -91,13 +87,13 @@ public function bind(HK1 $a, callable $f): Pair * @param A $aa * @return Pair */ - fn ($ca, $aa) => Pair::fromBrand($f($aa))->eval( + fn (mixed $ca, mixed $aa): Pair => Pair::fromBrand($f($aa))->eval( /** * @param C $c * @param B $b * @return Pair */ - fn ($c, $b) => Pair::pair($this->monoid->append($ca, $c), $b) + fn (mixed $c, mixed $b): Pair => Pair::pair($this->monoid->append($ca, $c), $b) ) ); } diff --git a/src/Instances/Reader/ReaderApplicative.php b/src/Instances/Reader/ReaderApplicative.php index ed4b6f2..2684eac 100644 --- a/src/Instances/Reader/ReaderApplicative.php +++ b/src/Instances/Reader/ReaderApplicative.php @@ -59,8 +59,8 @@ public function apply(HK1 $f, HK1 $a): Reader * * @psalm-suppress ImplementedReturnTypeMismatch */ - public function pure($a): Reader + public function pure(mixed $a): Reader { - return Reader::reader(static fn ($_) => $a); + return Reader::reader(static fn (mixed $_): mixed => $a); } } diff --git a/src/Instances/Reader/ReaderApply.php b/src/Instances/Reader/ReaderApply.php index 57f3ada..99c264d 100644 --- a/src/Instances/Reader/ReaderApply.php +++ b/src/Instances/Reader/ReaderApply.php @@ -55,7 +55,7 @@ public function apply(HK1 $f, HK1 $a): Reader * @param E $env * @return B */ - static fn ($env) => ($readerF->runReader($env))($readerA->runReader($env)) + static fn (mixed $env): mixed => ($readerF->runReader($env))($readerA->runReader($env)) ); } } diff --git a/src/Instances/Reader/ReaderFunctor.php b/src/Instances/Reader/ReaderFunctor.php index fe02555..21517c7 100644 --- a/src/Instances/Reader/ReaderFunctor.php +++ b/src/Instances/Reader/ReaderFunctor.php @@ -38,7 +38,7 @@ public function map(callable $f, HK1 $a): Reader * @param E $env * @return B */ - static fn ($env) => $f($readerA->runReader($env)) + static fn (mixed $env): mixed => $f($readerA->runReader($env)) ); } } diff --git a/src/Instances/Reader/ReaderMonad.php b/src/Instances/Reader/ReaderMonad.php index 8b1b953..fa11d49 100644 --- a/src/Instances/Reader/ReaderMonad.php +++ b/src/Instances/Reader/ReaderMonad.php @@ -59,7 +59,7 @@ public function apply(HK1 $f, HK1 $a): Reader * * @psalm-suppress ImplementedReturnTypeMismatch */ - public function pure($a): Reader + public function pure(mixed $a): Reader { return (new ReaderApplicative())->pure($a); } @@ -83,7 +83,7 @@ public function bind(HK1 $a, callable $f): Reader /** * @param E $env */ - static fn ($env) => Reader::fromBrand($f($readerA->runReader($env)))->runReader($env) + static fn (mixed $env): mixed => Reader::fromBrand($f($readerA->runReader($env)))->runReader($env) ); } } diff --git a/src/Instances/State/StateApplicative.php b/src/Instances/State/StateApplicative.php index fe0c290..2bcb59f 100644 --- a/src/Instances/State/StateApplicative.php +++ b/src/Instances/State/StateApplicative.php @@ -60,8 +60,8 @@ public function apply(HK1 $f, HK1 $a): State * * @psalm-suppress ImplementedReturnTypeMismatch */ - public function pure($a): State + public function pure(mixed $a): State { - return State::state(static fn ($s) => Pair::pair($s, $a)); + return State::state(static fn (mixed $s): Pair => Pair::pair($s, $a)); } } diff --git a/src/Instances/State/StateApply.php b/src/Instances/State/StateApply.php index 42e8cb4..b2bbfab 100644 --- a/src/Instances/State/StateApply.php +++ b/src/Instances/State/StateApply.php @@ -56,7 +56,7 @@ public function apply(HK1 $f, HK1 $a): State * @param S $s * @return Pair */ - static function ($s) use ($stateF, $stateA) { + static function (mixed $s) use ($stateF, $stateA) { $fs = $stateF->runState($s); return $fs->eval( @@ -65,12 +65,12 @@ static function ($s) use ($stateF, $stateA) { * @param callable(A): B $ff * @return Pair */ - static fn ($s1, callable $ff) => $stateA->runState($s1)->map( + static fn (mixed $s1, callable $ff): Pair => $stateA->runState($s1)->map( /** * @param A $aa * @return B */ - static fn ($aa) => $ff($aa) + static fn (mixed $aa): mixed => $ff($aa) ) ); } diff --git a/src/Instances/State/StateFunctor.php b/src/Instances/State/StateFunctor.php index 852e851..bc11a76 100644 --- a/src/Instances/State/StateFunctor.php +++ b/src/Instances/State/StateFunctor.php @@ -39,7 +39,7 @@ public function map(callable $f, HK1 $a): State * @param S $state * @return Pair */ - static fn ($state) => $stateA->runState($state)->map($f) + static fn (mixed $state): Pair => $stateA->runState($state)->map($f) ); } } diff --git a/src/Instances/State/StateMonad.php b/src/Instances/State/StateMonad.php index 690461a..a14c41c 100644 --- a/src/Instances/State/StateMonad.php +++ b/src/Instances/State/StateMonad.php @@ -59,7 +59,7 @@ public function apply(HK1 $f, HK1 $a): State * * @psalm-suppress ImplementedReturnTypeMismatch */ - public function pure($a): State + public function pure(mixed $a): State { return (new StateApplicative())->pure($a); } @@ -83,12 +83,12 @@ public function bind(HK1 $a, callable $f): State /** * @param S $s */ - static fn ($s) => $stateA->runState($s)->eval( + static fn (mixed $s): mixed => $stateA->runState($s)->eval( /** * @param S $ss * @param A $aa */ - static fn ($ss, $aa) => State::fromBrand($f($aa))->runState($ss) + static fn (mixed $ss, mixed $aa): mixed => State::fromBrand($f($aa))->runState($ss) ) ); } diff --git a/src/Instances/String/ConcatenationMonoid.php b/src/Instances/String/ConcatenationMonoid.php index 1dba9b6..b8597d1 100644 --- a/src/Instances/String/ConcatenationMonoid.php +++ b/src/Instances/String/ConcatenationMonoid.php @@ -22,7 +22,7 @@ public function mempty(): string * @param string $a * @param string $b */ - public function append($a, $b): string + public function append(mixed $a, mixed $b): string { return $a . $b; } diff --git a/src/Instances/Traversable/TraversableFoldable.php b/src/Instances/Traversable/TraversableFoldable.php index 6691b72..0d53a26 100644 --- a/src/Instances/Traversable/TraversableFoldable.php +++ b/src/Instances/Traversable/TraversableFoldable.php @@ -26,7 +26,7 @@ final class TraversableFoldable implements Foldable * * @psalm-pure */ - public function foldr(callable $f, $b, HK1 $a) + public function foldr(callable $f, mixed $b, HK1 $a): mixed { $arrayA = Traversable::fromBrand($a); diff --git a/src/Instances/Traversable/TraversableMonoid.php b/src/Instances/Traversable/TraversableMonoid.php index 0c9f4c1..7e700bb 100644 --- a/src/Instances/Traversable/TraversableMonoid.php +++ b/src/Instances/Traversable/TraversableMonoid.php @@ -30,7 +30,7 @@ public function mempty(): Traversable * * @psalm-pure */ - public function append($a, $b): Traversable + public function append(mixed $a, mixed $b): Traversable { $ret = []; diff --git a/src/LinkedList.php b/src/LinkedList.php index d179ab8..bf8ee63 100644 --- a/src/LinkedList.php +++ b/src/LinkedList.php @@ -36,24 +36,15 @@ */ final class LinkedList implements DefaultMonad, DefaultTraversable { - /** @var bool */ - private $isEmpty; - - /** @var null|A */ - private $head; - - /** @var null|LinkedList */ - private $tail; - /** * @param null|A $head * @param null|LinkedList $tail */ - private function __construct(bool $isEmpty, $head = null, ?self $tail = null) - { - $this->isEmpty = $isEmpty; - $this->head = $head; - $this->tail = $tail; + private function __construct( + private readonly bool $isEmpty, + private readonly mixed $head = null, + private readonly ?self $tail = null + ) { } /** @@ -75,7 +66,7 @@ public static function empty(): self * * @psalm-pure */ - public static function cons($head, self $tail): self + public static function cons(mixed $head, self $tail): self { return new self(false, $head, $tail); } @@ -115,7 +106,7 @@ public static function fromBrand(HK1 $b): self * @param B $unit * @return B */ - public function eval(callable $op, $unit) + public function eval(callable $op, mixed $unit) { if ($this->isEmpty) { return $unit; @@ -217,7 +208,7 @@ public function apply(HK1 $f): self * * @psalm-pure */ - public static function ipure(Applicative $applicative, $a): self + public static function ipure(Applicative $applicative, mixed $a): self { return self::fromBrand($applicative->pure($a)); } @@ -231,7 +222,7 @@ public static function ipure(Applicative $applicative, $a): self * * @psalm-suppress LessSpecificImplementedReturnType */ - public static function pure($a): self + public static function pure(mixed $a): self { return self::ipure(new LinkedListApplicative(), $a); } @@ -267,7 +258,7 @@ public function bind(callable $f): self * @param B $b * @return B */ - public function ifoldr(Foldable $foldable, callable $f, $b) + public function ifoldr(Foldable $foldable, callable $f, mixed $b) { /** @psalm-suppress ArgumentTypeCoercion */ return $foldable->foldr($f, $b, $this); @@ -279,7 +270,7 @@ public function ifoldr(Foldable $foldable, callable $f, $b) * @param B $b * @return B */ - public function foldr(callable $f, $b) + public function foldr(callable $f, mixed $b): mixed { return $this->ifoldr(new LinkedListFoldable(), $f, $b); } diff --git a/src/ListL.php b/src/ListL.php index e4f871d..7f89fb8 100644 --- a/src/ListL.php +++ b/src/ListL.php @@ -4,8 +4,6 @@ namespace Marcosh\LamPHPda; -use ArrayIterator; -use Iterator; use IteratorAggregate; use Marcosh\LamPHPda\Brand\ListBrand; use Marcosh\LamPHPda\HK\HK1; @@ -20,17 +18,13 @@ * * @psalm-immutable */ -final class ListL implements IteratorAggregate, HK1 +final class ListL implements \IteratorAggregate, HK1 { - /** @var list */ - private array $list; - /** * @param list $list */ - public function __construct(array $list) + public function __construct(private readonly array $list) { - $this->list = $list; } /** @@ -58,16 +52,16 @@ public function asNativeList(): array * @param A $a * @return ListL */ - public function append($a): self + public function append(mixed $a): self { - return new self(array_merge($this->list, [$a])); + return new self([...$this->list, ...[$a]]); } /** - * @return Iterator + * @return \Iterator */ - public function getIterator(): Iterator + public function getIterator(): \Iterator { - return new ArrayIterator($this->list); + return new \ArrayIterator($this->list); } } diff --git a/src/Maybe.php b/src/Maybe.php index 5194939..bbd6f84 100644 --- a/src/Maybe.php +++ b/src/Maybe.php @@ -34,18 +34,11 @@ */ final class Maybe implements DefaultMonad, DefaultTraversable { - private bool $isJust; - - /** @var null|A */ - private $value; - /** * @param null|A $value */ - private function __construct(bool $isJust, $value = null) + private function __construct(private readonly bool $isJust, private readonly mixed $value = null) { - $this->isJust = $isJust; - $this->value = $value; } /** @@ -91,7 +84,7 @@ public static function fromBrand(HK1 $b): self * @param null|B $a * @return Maybe */ - public static function fromNullable($a): self + public static function fromNullable(mixed $a): self { if (null === $a) { return self::nothing(); @@ -109,7 +102,7 @@ public static function fromNullable($a): self public function eval( $ifNothing, callable $ifJust - ) { + ): mixed { if ($this->isJust) { /** * @psalm-suppress PossiblyNullArgument @@ -125,7 +118,7 @@ public function eval( * @param A $a * @return A */ - public function withDefault($a) + public function withDefault(mixed $a): mixed { return $this->eval( $a, @@ -133,7 +126,7 @@ public function withDefault($a) * @param A $a * @return A */ - static fn ($a) => $a + static fn (mixed $a): mixed => $a ); } @@ -141,7 +134,7 @@ public function withDefault($a) * @param callable(): A $a * @return A */ - public function withLazyDefault(callable $a) + public function withLazyDefault(callable $a): mixed { // This can be implemented in terms of eval(), however the actual implementation is optimized: // return $this->eval($ifNothing, fn($value) => fn() => $ifJust($value))(); @@ -159,11 +152,11 @@ public function withLazyDefault(callable $a) * @param B $b * @return Either */ - public function toEither($b): Either + public function toEither(mixed $b): Either { return $this->eval( Either::left($b), - static fn ($a): Either => Either::right($a) + static fn (mixed $a): Either => Either::right($a) ); } @@ -237,7 +230,7 @@ public static function ipure(Applicative $applicative, $a): self * * @psalm-suppress LessSpecificImplementedReturnType */ - public static function pure($a): self + public static function pure(mixed $a): self { return self::ipure(new MaybeApplicative(), $a); } @@ -273,7 +266,7 @@ public function bind(callable $f): self * @param B $b * @return B */ - public function ifoldr(Foldable $foldable, callable $f, $b) + public function ifoldr(Foldable $foldable, callable $f, mixed $b) { /** @psalm-suppress ArgumentTypeCoercion */ return $foldable->foldr($f, $b, $this); @@ -285,7 +278,7 @@ public function ifoldr(Foldable $foldable, callable $f, $b) * @param B $b * @return B */ - public function foldr(callable $f, $b) + public function foldr(callable $f, mixed $b): mixed { return $this->ifoldr(new MaybeFoldable(), $f, $b); } diff --git a/src/Pair.php b/src/Pair.php index aea5116..3d29645 100644 --- a/src/Pair.php +++ b/src/Pair.php @@ -33,20 +33,12 @@ */ final class Pair implements DefaultFunctor, HK2Covariant { - /** @var A */ - private $left; - - /** @var B */ - private $right; - /** * @param A $left * @param B $right */ - private function __construct($left, $right) + private function __construct(private readonly mixed $left, private readonly mixed $right) { - $this->left = $left; - $this->right = $right; } /** @@ -58,7 +50,7 @@ private function __construct($left, $right) * * @psalm-pure */ - public static function pair($left, $right): self + public static function pair(mixed $left, mixed $right): self { return new self($left, $right); } @@ -96,7 +88,7 @@ public static function fromBrand2(HK2Covariant $hk): self * @param callable(A, B): C $f * @return C */ - public function eval(callable $f) + public function eval(callable $f): mixed { /** @psalm-suppress ImpureFunctionCall */ return $f($this->left, $this->right); @@ -105,7 +97,7 @@ public function eval(callable $f) /** * @return A */ - public function first() + public function first(): mixed { return $this->eval( /** @@ -113,14 +105,14 @@ public function first() * @param B $_ * @return A */ - static fn ($a, $_) => $a + static fn (mixed $a, mixed $_): mixed => $a ); } /** * @return B */ - public function second() + public function second(): mixed { return $this->eval( /** @@ -128,7 +120,7 @@ public function second() * @param B $b * @return B */ - static fn ($_, $b) => $b + static fn (mixed $_, mixed $b): mixed => $b ); } @@ -184,7 +176,7 @@ public function apply(Semigroup $semigroup, HK1 $f): self * * @psalm-pure */ - public static function ipure(Applicative $applicative, $a): self + public static function ipure(Applicative $applicative, mixed $a): self { return self::fromBrand($applicative->pure($a)); } @@ -198,7 +190,7 @@ public static function ipure(Applicative $applicative, $a): self * * @psalm-pure */ - public static function pure(Monoid $monoid, $a): self + public static function pure(Monoid $monoid, mixed $a): self { return self::ipure(new PairApplicative($monoid), $a); } diff --git a/src/Reader.php b/src/Reader.php index 880f56f..1f35865 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -70,7 +70,7 @@ public static function fromBrand(HK1 $b): self * @param E $environment * @return A */ - public function runReader($environment) + public function runReader(mixed $environment): mixed { /** @psalm-suppress ImpureFunctionCall */ return ($this->action)($environment); @@ -86,7 +86,7 @@ public function ask(): self * @param E $e * @return E */ - static fn ($e) => $e + static fn (mixed $e): mixed => $e ); } @@ -141,7 +141,7 @@ public function apply(HK1 $f): self * * @psalm-pure */ - public static function ipure(Applicative $applicative, $a): self + public static function ipure(Applicative $applicative, mixed $a): self { return self::fromBrand($applicative->pure($a)); } @@ -154,7 +154,7 @@ public static function ipure(Applicative $applicative, $a): self * * @psalm-pure */ - public static function pure($a): self + public static function pure(mixed $a): self { return self::ipure(new ReaderApplicative(), $a); } diff --git a/src/State.php b/src/State.php index b9baa0a..3aea5f6 100644 --- a/src/State.php +++ b/src/State.php @@ -70,7 +70,7 @@ public static function fromBrand(HK1 $b): self * @param S $state * @return Pair */ - public function runState($state): Pair + public function runState(mixed $state): Pair { /** @psalm-suppress ImpureFunctionCall */ return ($this->runState)($state); @@ -80,7 +80,7 @@ public function runState($state): Pair * @param S $state * @return A */ - public function evalState($state) + public function evalState(mixed $state): mixed { return $this->runState($state)->second(); } @@ -89,7 +89,7 @@ public function evalState($state) * @param S $state * @return S */ - public function execState($state) + public function execState(mixed $state): mixed { return $this->runState($state)->first(); } @@ -145,7 +145,7 @@ public function apply(HK1 $f): self * * @psalm-pure */ - public static function ipure(Applicative $applicative, $a): self + public static function ipure(Applicative $applicative, mixed $a): self { return self::fromBrand($applicative->pure($a)); } @@ -158,7 +158,7 @@ public static function ipure(Applicative $applicative, $a): self * * @psalm-pure */ - public static function pure($a): self + public static function pure(mixed $a): self { return self::ipure(new StateApplicative(), $a); } diff --git a/src/Traversable.php b/src/Traversable.php index 70fd43d..ae743dd 100644 --- a/src/Traversable.php +++ b/src/Traversable.php @@ -4,7 +4,6 @@ namespace Marcosh\LamPHPda; -use ArrayIterator; use IteratorAggregate; use Marcosh\LamPHPda\Brand\TraversableBrand; use Marcosh\LamPHPda\HK\HK1; @@ -21,17 +20,13 @@ * * @psalm-immutable */ -final class Traversable implements IteratorAggregate, DefaultFoldable +final class Traversable implements \IteratorAggregate, DefaultFoldable { - /** @var PhpTraversable */ - private PhpTraversable $traversable; - /** * @param PhpTraversable $traversable */ - private function __construct(PhpTraversable $traversable) + private function __construct(private readonly PhpTraversable $traversable) { - $this->traversable = $traversable; } /** @@ -56,7 +51,7 @@ public static function fromPhpTraversable(PhpTraversable $traversable): self public static function fromArray(array $array): self { /** @psalm-suppress ImpureMethodCall */ - return new self(new ArrayIterator($array)); + return new self(new \ArrayIterator($array)); } /** @@ -89,7 +84,7 @@ public static function fromBrand(HK1 $hk): self * * @psalm-mutation-free */ - public function ifoldr(Foldable $foldable, callable $f, $b) + public function ifoldr(Foldable $foldable, callable $f, mixed $b): mixed { return $foldable->foldr($f, $b, $this); } @@ -102,7 +97,7 @@ public function ifoldr(Foldable $foldable, callable $f, $b) * * @psalm-mutation-free */ - public function foldr(callable $f, $b) + public function foldr(callable $f, mixed $b): mixed { return $this->ifoldr(new TraversableFoldable(), $f, $b); } diff --git a/src/Typeclass/Applicative.php b/src/Typeclass/Applicative.php index 2997248..c53f426 100644 --- a/src/Typeclass/Applicative.php +++ b/src/Typeclass/Applicative.php @@ -25,5 +25,5 @@ interface Applicative extends Apply * * @psalm-pure */ - public function pure($a): HK1; + public function pure(mixed $a): HK1; } diff --git a/src/Typeclass/DefaultInstance/DefaultApplicative.php b/src/Typeclass/DefaultInstance/DefaultApplicative.php index cf0a283..a8df54b 100644 --- a/src/Typeclass/DefaultInstance/DefaultApplicative.php +++ b/src/Typeclass/DefaultInstance/DefaultApplicative.php @@ -24,5 +24,5 @@ interface DefaultApplicative extends DefaultApply * * @psalm-pure */ - public static function pure($a): HK1; + public static function pure(mixed $a): HK1; } diff --git a/src/Typeclass/DefaultInstance/DefaultFoldable.php b/src/Typeclass/DefaultInstance/DefaultFoldable.php index 6a302ea..4d1c13c 100644 --- a/src/Typeclass/DefaultInstance/DefaultFoldable.php +++ b/src/Typeclass/DefaultInstance/DefaultFoldable.php @@ -23,5 +23,5 @@ interface DefaultFoldable extends HK1 * @param B $b * @return B */ - public function foldr(callable $f, $b); + public function foldr(callable $f, mixed $b): mixed; } diff --git a/src/Typeclass/Extra/ExtraApply.php b/src/Typeclass/Extra/ExtraApply.php index 72eccd3..d012151 100644 --- a/src/Typeclass/Extra/ExtraApply.php +++ b/src/Typeclass/Extra/ExtraApply.php @@ -15,15 +15,11 @@ */ final class ExtraApply { - /** @var Apply */ - private Apply $apply; - /** * @param Apply $apply */ - public function __construct(Apply $apply) + public function __construct(private readonly Apply $apply) { - $this->apply = $apply; } /** @@ -42,12 +38,12 @@ public function lift2(callable $f, HK1 $a, HK1 $b): HK1 * @param A $ca * @return callable(B): C */ - static fn ($ca) => + static fn (mixed $ca): \Closure => /** * @param B $cb * @return C */ - static fn ($cb) => $f($ca, $cb); + static fn (mixed $cb): mixed => $f($ca, $cb); return $this->apply->apply( $this->apply->map($curriedF, $a), @@ -73,17 +69,17 @@ public function lift3(callable $f, HK1 $a, HK1 $b, HK1 $c): HK1 * @param A $ca * @return callable(B): (callable(C): D) */ - static fn ($ca) => + static fn (mixed $ca): \Closure => /** * @param B $cb * @return callable(C): D */ - static fn ($cb) => + static fn (mixed $cb): \Closure => /** * @param C $cc * @return D */ - static fn ($cc) => $f($ca, $cb, $cc); + static fn (mixed $cc): mixed => $f($ca, $cb, $cc); return $this->apply->apply( $this->apply->apply( @@ -114,22 +110,22 @@ public function lift4(callable $f, HK1 $a, HK1 $b, HK1 $c, HK1 $d): HK1 * @param A $ca * @return callable(B): (callable(C): (callable(D): E)) */ - static fn ($ca) => + static fn (mixed $ca): \Closure => /** * @param B $cb * @return callable(C): (callable(D): E) */ - static fn ($cb) => + static fn (mixed $cb): \Closure => /** * @param C $cc * @return callable(D): E */ - static fn ($cc) => + static fn (mixed $cc): \Closure => /** * @param D $cd * @return E */ - static fn ($cd) => $f($ca, $cb, $cc, $cd); + static fn (mixed $cd): mixed => $f($ca, $cb, $cc, $cd); return $this->apply->apply( $this->apply->apply( @@ -165,27 +161,27 @@ public function lift5(callable $f, HK1 $a, HK1 $b, HK1 $c, HK1 $d, HK1 $e): HK1 * @param A $ca * @return callable(B): (callable(C): (callable(D): (callable(E): G))) */ - static fn ($ca) => + static fn (mixed $ca): \Closure => /** * @param B $cb * @return callable(C): (callable(D): (callable(E): G)) */ - static fn ($cb) => + static fn (mixed $cb): \Closure => /** * @param C $cc * @return callable(D): (callable(E): G) */ - static fn ($cc) => + static fn (mixed $cc): \Closure => /** * @param D $cd * @return callable(E): G */ - static fn ($cd) => + static fn (mixed $cd): \Closure => /** * @param E $ce * @return G */ - static fn ($ce) => $f($ca, $cb, $cc, $cd, $ce); + static fn (mixed $ce): mixed => $f($ca, $cb, $cc, $cd, $ce); return $this->apply->apply( $this->apply->apply( @@ -226,32 +222,32 @@ public function lift6(callable $f, HK1 $a, HK1 $b, HK1 $c, HK1 $d, HK1 $e, HK1 $ * @param A $ca * @return callable(B): (callable(C): (callable(D): (callable(E): (callable(G): H)))) */ - static fn ($ca) => + static fn (mixed $ca): \Closure => /** * @param B $cb * @return callable(C): (callable(D): (callable(E): (callable(G): H))) */ - static fn ($cb) => + static fn (mixed $cb): \Closure => /** * @param C $cc * @return callable(D): (callable(E): (callable(G): H)) */ - static fn ($cc) => + static fn (mixed $cc): \Closure => /** * @param D $cd * @return callable(E): (callable(G): H) */ - static fn ($cd) => + static fn (mixed $cd): \Closure => /** * @param E $ce * @return callable(G): H */ - static fn ($ce) => + static fn (mixed $ce): \Closure => /** * @param G $cg * @return H */ - static fn ($cg) => $f($ca, $cb, $cc, $cd, $ce, $cg); + static fn (mixed $cg): mixed => $f($ca, $cb, $cc, $cd, $ce, $cg); return $this->apply->apply( $this->apply->apply( @@ -297,37 +293,37 @@ public function lift7(callable $f, HK1 $a, HK1 $b, HK1 $c, HK1 $d, HK1 $e, HK1 $ * @param A $ca * @return callable(B): (callable(C): (callable(D): (callable(E): (callable(G): (callable(H): I))))) */ - static fn ($ca) => + static fn (mixed $ca): \Closure => /** * @param B $cb * @return callable(C): (callable(D): (callable(E): (callable(G): (callable(H): I)))) */ - static fn ($cb) => + static fn (mixed $cb): \Closure => /** * @param C $cc * @return callable(D): (callable(E): (callable(G): (callable(H): I))) */ - static fn ($cc) => + static fn (mixed $cc): \Closure => /** * @param D $cd * @return callable(E): (callable(G): (callable(H): I)) */ - static fn ($cd) => + static fn (mixed $cd): \Closure => /** * @param E $ce * @return callable(G): (callable(H): I) */ - static fn ($ce) => + static fn (mixed $ce): \Closure => /** * @param G $cg * @return callable(H): I */ - static fn ($cg) => + static fn (mixed $cg): \Closure => /** * @param H $ch * @return I */ - static fn ($ch) => $f($ca, $cb, $cc, $cd, $ce, $cg, $ch); + static fn (mixed $ch): mixed => $f($ca, $cb, $cc, $cd, $ce, $cg, $ch); return $this->apply->apply( $this->apply->apply( @@ -378,42 +374,42 @@ public function lift8(callable $f, HK1 $a, HK1 $b, HK1 $c, HK1 $d, HK1 $e, HK1 $ * @param A $ca * @return callable(B): (callable(C): (callable(D): (callable(E): (callable(G): (callable(H): (callable(I): J)))))) */ - static fn ($ca) => + static fn (mixed $ca): \Closure => /** * @param B $cb * @return callable(C): (callable(D): (callable(E): (callable(G): (callable(H): (callable(I): J))))) */ - static fn ($cb) => + static fn (mixed $cb): \Closure => /** * @param C $cc * @return callable(D): (callable(E): (callable(G): (callable(H): (callable(I): J)))) */ - static fn ($cc) => + static fn (mixed $cc): \Closure => /** * @param D $cd * @return callable(E): (callable(G): (callable(H): (callable(I): J))) */ - static fn ($cd) => + static fn (mixed $cd): \Closure => /** * @param E $ce * @return callable(G): (callable(H): (callable(I): J)) */ - static fn ($ce) => + static fn (mixed $ce): \Closure => /** * @param G $cg * @return callable(H): (callable(I): J) */ - static fn ($cg) => + static fn (mixed $cg): \Closure => /** * @param H $ch * @return callable(I): J */ - static fn ($ch) => + static fn (mixed $ch): \Closure => /** * @param I $ci * @return J */ - static fn ($ci) => $f($ca, $cb, $cc, $cd, $ce, $cg, $ch, $ci); + static fn (mixed $ci): mixed => $f($ca, $cb, $cc, $cd, $ce, $cg, $ch, $ci); return $this->apply->apply( $this->apply->apply( diff --git a/src/Typeclass/Extra/ExtraBifunctor.php b/src/Typeclass/Extra/ExtraBifunctor.php index 9a26016..47aa667 100644 --- a/src/Typeclass/Extra/ExtraBifunctor.php +++ b/src/Typeclass/Extra/ExtraBifunctor.php @@ -15,15 +15,11 @@ */ final class ExtraBifunctor { - /** @var Bifunctor */ - private Bifunctor $bifunctor; - /** * @param Bifunctor $bifunctor */ - public function __construct(Bifunctor $bifunctor) + public function __construct(private readonly Bifunctor $bifunctor) { - $this->bifunctor = $bifunctor; } /** @@ -62,7 +58,7 @@ public function second(callable $g, HK2Covariant $hk2): HK2Covariant * @param A $a * @return A */ - static fn ($a) => $a, + static fn (mixed $a) => $a, $g, $hk2 ); diff --git a/src/Typeclass/Extra/ExtraMonad.php b/src/Typeclass/Extra/ExtraMonad.php index 2bad014..37694b7 100644 --- a/src/Typeclass/Extra/ExtraMonad.php +++ b/src/Typeclass/Extra/ExtraMonad.php @@ -15,15 +15,11 @@ */ final class ExtraMonad { - /** @var Monad */ - private Monad $monad; - /** * @param Monad $monad */ - public function __construct(Monad $monad) + public function __construct(private readonly Monad $monad) { - $this->monad = $monad; } /** diff --git a/src/Typeclass/Extra/ExtraProfunctor.php b/src/Typeclass/Extra/ExtraProfunctor.php index 5ad7b7b..41d3306 100644 --- a/src/Typeclass/Extra/ExtraProfunctor.php +++ b/src/Typeclass/Extra/ExtraProfunctor.php @@ -15,15 +15,11 @@ */ final class ExtraProfunctor { - /** @var Profunctor */ - private Profunctor $profunctor; - /** * @param Profunctor $profunctor */ - public function __construct(Profunctor $profunctor) + public function __construct(private readonly Profunctor $profunctor) { - $this->profunctor = $profunctor; } /** diff --git a/src/Typeclass/Extra/ExtraTraversable.php b/src/Typeclass/Extra/ExtraTraversable.php index 38b3074..fa68191 100644 --- a/src/Typeclass/Extra/ExtraTraversable.php +++ b/src/Typeclass/Extra/ExtraTraversable.php @@ -16,15 +16,11 @@ */ final class ExtraTraversable { - /** @var Traversable */ - private $traversable; - /** * @param Traversable $traversable */ - public function __construct(Traversable $traversable) + public function __construct(private readonly Traversable $traversable) { - $this->traversable = $traversable; } /** diff --git a/src/Typeclass/Foldable.php b/src/Typeclass/Foldable.php index 68ef3d6..fa0c688 100644 --- a/src/Typeclass/Foldable.php +++ b/src/Typeclass/Foldable.php @@ -24,5 +24,5 @@ interface Foldable * @param HK1 $a * @return B */ - public function foldr(callable $f, $b, HK1 $a); + public function foldr(callable $f, mixed $b, HK1 $a): mixed; } diff --git a/src/Typeclass/MonadThrow.php b/src/Typeclass/MonadThrow.php index cdf0f29..2175132 100644 --- a/src/Typeclass/MonadThrow.php +++ b/src/Typeclass/MonadThrow.php @@ -24,5 +24,5 @@ interface MonadThrow extends Monad * @param E $e * @return HK1 */ - public function throwError($e): HK1; + public function throwError(mixed $e): HK1; } diff --git a/src/Typeclass/Monoid.php b/src/Typeclass/Monoid.php index df293b9..42c16dc 100644 --- a/src/Typeclass/Monoid.php +++ b/src/Typeclass/Monoid.php @@ -20,5 +20,5 @@ interface Monoid extends Semigroup * * @psalm-pure */ - public function mempty(); + public function mempty(): mixed; } diff --git a/src/Typeclass/Semigroup.php b/src/Typeclass/Semigroup.php index efbfb5c..f19290d 100644 --- a/src/Typeclass/Semigroup.php +++ b/src/Typeclass/Semigroup.php @@ -20,5 +20,5 @@ interface Semigroup * * @psalm-pure */ - public function append($a, $b); + public function append(mixed $a, mixed $b): mixed; }