From 9eea52f362eee027423e44841374cb90be7b8754 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Mon, 5 Jul 2021 11:27:27 +0100 Subject: [PATCH 1/4] Main immutable and pure annotations --- src/Collection.php | 2 ++ src/Contract/Collection.php | 2 ++ src/Operation/AbstractOperation.php | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/Collection.php b/src/Collection.php index 790e4cf1a..d7aac918b 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -136,6 +136,8 @@ * @template TKey * @template T * + * @psalm-immutable + * * phpcs:disable Generic.Files.LineLength.TooLong * * @implements \loophp\collection\Contract\Collection diff --git a/src/Contract/Collection.php b/src/Contract/Collection.php index 67ccbca78..565820c06 100644 --- a/src/Contract/Collection.php +++ b/src/Contract/Collection.php @@ -127,6 +127,8 @@ * @template TKey * @template T * + * @psalm-immutable + * * @template-extends Allable * @template-extends Appendable * @template-extends Applyable diff --git a/src/Operation/AbstractOperation.php b/src/Operation/AbstractOperation.php index 0300d0a08..2fab53111 100644 --- a/src/Operation/AbstractOperation.php +++ b/src/Operation/AbstractOperation.php @@ -12,12 +12,16 @@ use Closure; use loophp\collection\Contract\Operation; +/** + * @immutable + */ abstract class AbstractOperation implements Operation { final public function __construct() { } + /** @pure */ public static function of(): Closure { return (new static())->__invoke(); From bb12a7efc18a552b3bd43e5b9e21ca82d2583faf Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Mon, 5 Jul 2021 12:08:27 +0100 Subject: [PATCH 2/4] Add @immutable & @pure annotations --- src/Collection.php | 15 +++++++++++++-- src/Contract/Collection.php | 4 ++-- src/Contract/Operation.php | 3 +++ src/Contract/Operation/Squashable.php | 2 ++ src/Operation/AbstractOperation.php | 1 + src/Operation/Append.php | 4 ++++ src/Operation/Apply.php | 4 ++++ src/Operation/Associate.php | 4 ++++ src/Operation/AsyncMap.php | 4 +++- src/Operation/Cache.php | 4 ++++ src/Operation/Chunk.php | 4 ++++ src/Operation/Coalesce.php | 4 ++++ src/Operation/Collapse.php | 4 ++++ src/Operation/Column.php | 4 ++++ src/Operation/Combinate.php | 5 +++++ src/Operation/Combine.php | 4 ++++ src/Operation/Compact.php | 4 ++++ src/Operation/Contains.php | 4 ++++ src/Operation/Current.php | 4 ++++ src/Operation/Cycle.php | 4 ++++ src/Operation/Diff.php | 4 ++++ src/Operation/DiffKeys.php | 4 ++++ src/Operation/Distinct.php | 4 ++++ src/Operation/Drop.php | 4 ++++ src/Operation/DropWhile.php | 4 ++++ src/Operation/Dump.php | 4 ++++ src/Operation/Duplicate.php | 4 ++++ src/Operation/Every.php | 4 ++++ src/Operation/Explode.php | 4 ++++ src/Operation/Falsy.php | 4 ++++ src/Operation/Filter.php | 4 ++++ src/Operation/First.php | 4 ++++ src/Operation/FlatMap.php | 4 ++++ src/Operation/Flatten.php | 4 ++++ src/Operation/Flip.php | 4 ++++ src/Operation/FoldLeft.php | 4 ++++ src/Operation/FoldLeft1.php | 4 ++++ src/Operation/FoldRight.php | 4 ++++ src/Operation/FoldRight1.php | 4 ++++ src/Operation/Forget.php | 4 ++++ src/Operation/Frequency.php | 4 ++++ src/Operation/Get.php | 4 ++++ src/Operation/Group.php | 4 ++++ src/Operation/GroupBy.php | 4 ++++ src/Operation/Has.php | 4 ++++ src/Operation/Head.php | 4 ++++ src/Operation/IfThenElse.php | 4 ++++ src/Operation/Implode.php | 4 ++++ src/Operation/Init.php | 4 ++++ src/Operation/Inits.php | 4 ++++ src/Operation/Intersect.php | 4 ++++ src/Operation/IntersectKeys.php | 4 ++++ src/Operation/Intersperse.php | 4 ++++ src/Operation/Key.php | 4 ++++ src/Operation/Keys.php | 4 ++++ src/Operation/Last.php | 4 ++++ src/Operation/Limit.php | 4 ++++ src/Operation/Lines.php | 4 ++++ src/Operation/Map.php | 4 ++++ src/Operation/MapN.php | 4 ++++ src/Operation/MatchOne.php | 4 ++++ src/Operation/Matching.php | 4 ++++ src/Operation/Merge.php | 4 ++++ src/Operation/Normalize.php | 4 ++++ src/Operation/Nth.php | 4 ++++ src/Operation/Nullsy.php | 4 ++++ src/Operation/Pack.php | 4 ++++ src/Operation/Pad.php | 4 ++++ src/Operation/Pair.php | 4 ++++ src/Operation/Partition.php | 4 ++++ src/Operation/Permutate.php | 5 +++++ src/Operation/Pipe.php | 4 ++++ src/Operation/Pluck.php | 4 ++++ src/Operation/Prepend.php | 4 ++++ src/Operation/Product.php | 5 +++++ src/Operation/RSample.php | 4 ++++ src/Operation/Random.php | 4 ++++ src/Operation/Range.php | 4 ++++ src/Operation/Reduction.php | 4 ++++ src/Operation/Reverse.php | 4 ++++ src/Operation/Scale.php | 4 ++++ src/Operation/ScanLeft.php | 4 ++++ src/Operation/ScanLeft1.php | 4 ++++ src/Operation/ScanRight.php | 4 ++++ src/Operation/ScanRight1.php | 4 ++++ src/Operation/Shuffle.php | 4 ++++ src/Operation/Since.php | 4 ++++ src/Operation/Slice.php | 4 ++++ src/Operation/Sort.php | 4 ++++ src/Operation/Span.php | 4 ++++ src/Operation/Split.php | 4 ++++ src/Operation/Strict.php | 4 ++++ src/Operation/Tail.php | 4 ++++ src/Operation/Tails.php | 4 ++++ src/Operation/TakeWhile.php | 4 ++++ src/Operation/Times.php | 4 ++++ src/Operation/Transpose.php | 4 ++++ src/Operation/Truthy.php | 4 ++++ src/Operation/Unfold.php | 4 ++++ src/Operation/Unlines.php | 4 ++++ src/Operation/Unpack.php | 4 ++++ src/Operation/Unpair.php | 4 ++++ src/Operation/Until.php | 4 ++++ src/Operation/Unwindow.php | 4 ++++ src/Operation/Unwords.php | 4 ++++ src/Operation/Unwrap.php | 4 ++++ src/Operation/Unzip.php | 4 ++++ src/Operation/When.php | 4 ++++ src/Operation/Window.php | 4 ++++ src/Operation/Words.php | 4 ++++ src/Operation/Wrap.php | 4 ++++ src/Operation/Zip.php | 4 ++++ 112 files changed, 451 insertions(+), 5 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index d7aac918b..eaaf6f35b 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -133,11 +133,11 @@ use const PHP_INT_MIN; /** + * @immutable + * * @template TKey * @template T * - * @psalm-immutable - * * phpcs:disable Generic.Files.LineLength.TooLong * * @implements \loophp\collection\Contract\Collection @@ -155,6 +155,8 @@ final class Collection implements CollectionInterface private $source; /** + * @psalm-external-mutation-free + * * @param callable(mixed ...$parameters): iterable $callable * @param mixed ...$parameters */ @@ -402,6 +404,7 @@ public function frequency(): CollectionInterface } /** + * @pure * @template NewTKey * @template NewT * @@ -416,6 +419,8 @@ public static function fromCallable(callable $callable, ...$parameters): self } /** + * @pure + * * @return self */ public static function fromFile(string $filepath): self @@ -427,6 +432,8 @@ public static function fromFile(string $filepath): self } /** + * @pure + * * @template NewTKey * @template NewT * @@ -443,6 +450,8 @@ public static function fromIterable(iterable $iterable): self } /** + * @pure + * * @param resource $resource * * @return self @@ -459,6 +468,8 @@ public static function fromResource($resource): self } /** + * @pure + * * @return self */ public static function fromString(string $string, string $delimiter = ''): self diff --git a/src/Contract/Collection.php b/src/Contract/Collection.php index 565820c06..44d1f3b87 100644 --- a/src/Contract/Collection.php +++ b/src/Contract/Collection.php @@ -124,11 +124,11 @@ use loophp\collection\Contract\Operation\Zipable; /** + * @immutable + * * @template TKey * @template T * - * @psalm-immutable - * * @template-extends Allable * @template-extends Appendable * @template-extends Applyable diff --git a/src/Contract/Operation.php b/src/Contract/Operation.php index 4f524c67a..4397fc6b1 100644 --- a/src/Contract/Operation.php +++ b/src/Contract/Operation.php @@ -11,9 +11,12 @@ use Closure; +/** @immutable */ interface Operation { + /** @pure */ public function __invoke(): Closure; + /** @pure */ public static function of(): Closure; } diff --git a/src/Contract/Operation/Squashable.php b/src/Contract/Operation/Squashable.php index cb0804b37..d61678a5a 100644 --- a/src/Contract/Operation/Squashable.php +++ b/src/Contract/Operation/Squashable.php @@ -12,6 +12,8 @@ use loophp\collection\Contract\Collection; /** + * @immutable + * * @template TKey * @template T */ diff --git a/src/Operation/AbstractOperation.php b/src/Operation/AbstractOperation.php index 2fab53111..c09e66fcb 100644 --- a/src/Operation/AbstractOperation.php +++ b/src/Operation/AbstractOperation.php @@ -17,6 +17,7 @@ */ abstract class AbstractOperation implements Operation { + /** @pure */ final public function __construct() { } diff --git a/src/Operation/Append.php b/src/Operation/Append.php index 364d23575..91525db39 100644 --- a/src/Operation/Append.php +++ b/src/Operation/Append.php @@ -14,12 +14,16 @@ use loophp\collection\Iterator\MultipleIterableIterator; /** + * @immutable + * * @template TKey * @template T */ final class Append extends AbstractOperation { /** + * @pure + * * @return Closure(T...): Closure(Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/Apply.php b/src/Operation/Apply.php index eae133194..646cb4125 100644 --- a/src/Operation/Apply.php +++ b/src/Operation/Apply.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Apply extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator):bool ...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Associate.php b/src/Operation/Associate.php index 324f9eb1b..ea3ff9bfb 100644 --- a/src/Operation/Associate.php +++ b/src/Operation/Associate.php @@ -15,6 +15,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -23,6 +25,8 @@ final class Associate extends AbstractOperation { /** + * @pure + * * @return Closure(callable(TKey, TKey, T, Iterator): (T|TKey) ...): Closure((callable(T, TKey, T, Iterator): (T|TKey))...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/AsyncMap.php b/src/Operation/AsyncMap.php index ea9c5abca..2484af4e6 100644 --- a/src/Operation/AsyncMap.php +++ b/src/Operation/AsyncMap.php @@ -27,7 +27,7 @@ } // phpcs:enable /** - * Class AsyncMap. + * @immutable * * @template TKey * @template T @@ -37,6 +37,8 @@ final class AsyncMap extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey): T ...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Cache.php b/src/Operation/Cache.php index 120f878d1..3f116128f 100644 --- a/src/Operation/Cache.php +++ b/src/Operation/Cache.php @@ -15,6 +15,8 @@ use Psr\Cache\CacheItemPoolInterface; /** + * @immutable + * * @template TKey * @template T * @@ -23,6 +25,8 @@ final class Cache extends AbstractOperation { /** + * @pure + * * @return Closure(CacheItemPoolInterface): Closure(Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/Chunk.php b/src/Operation/Chunk.php index 452a9da0b..e998d41b1 100644 --- a/src/Operation/Chunk.php +++ b/src/Operation/Chunk.php @@ -18,12 +18,16 @@ use function count; /** + * @immutable + * * @template TKey * @template T */ final class Chunk extends AbstractOperation { /** + * @pure + * * @return Closure(int...): Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Coalesce.php b/src/Operation/Coalesce.php index 250696938..e3a51952d 100644 --- a/src/Operation/Coalesce.php +++ b/src/Operation/Coalesce.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Coalesce extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Collapse.php b/src/Operation/Collapse.php index eddf693d9..b77855262 100644 --- a/src/Operation/Collapse.php +++ b/src/Operation/Collapse.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Collapse extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator)>): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Column.php b/src/Operation/Column.php index bc71c8d17..6affa3297 100644 --- a/src/Operation/Column.php +++ b/src/Operation/Column.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Column extends AbstractOperation { /** + * @pure + * * @return Closure(T): Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Combinate.php b/src/Operation/Combinate.php index 90cd542b4..90b22b597 100644 --- a/src/Operation/Combinate.php +++ b/src/Operation/Combinate.php @@ -17,11 +17,16 @@ use function count; /** + * @immutable + * * @template TKey * @template T */ final class Combinate extends AbstractOperation { + /** + * @pure + */ public function __invoke(): Closure { return static function (?int $length = null): Closure { diff --git a/src/Operation/Combine.php b/src/Operation/Combine.php index 927b97502..52c59bf25 100644 --- a/src/Operation/Combine.php +++ b/src/Operation/Combine.php @@ -17,12 +17,16 @@ use const E_USER_WARNING; /** + * @immutable + * * @template TKey * @template T */ final class Combine extends AbstractOperation { /** + * @pure + * * @return Closure(T...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Compact.php b/src/Operation/Compact.php index 342e73da0..c31307481 100644 --- a/src/Operation/Compact.php +++ b/src/Operation/Compact.php @@ -16,6 +16,8 @@ use function in_array; /** + * @immutable + * * @template TKey * @template T * @@ -24,6 +26,8 @@ final class Compact extends AbstractOperation { /** + * @pure + * * @return Closure(T...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Contains.php b/src/Operation/Contains.php index e28e57e2a..1cf1d7a6e 100644 --- a/src/Operation/Contains.php +++ b/src/Operation/Contains.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Contains extends AbstractOperation { /** + * @pure + * * @return Closure(T ...$values): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Current.php b/src/Operation/Current.php index de1251681..4c8900408 100644 --- a/src/Operation/Current.php +++ b/src/Operation/Current.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Current extends AbstractOperation { /** + * @pure + * * @return Closure(int $index): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Cycle.php b/src/Operation/Cycle.php index fdbc9528c..831786960 100644 --- a/src/Operation/Cycle.php +++ b/src/Operation/Cycle.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Cycle extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/Diff.php b/src/Operation/Diff.php index 9795deb1a..daf3e2f93 100644 --- a/src/Operation/Diff.php +++ b/src/Operation/Diff.php @@ -16,12 +16,16 @@ use function in_array; /** + * @immutable + * * @template TKey * @template T */ final class Diff extends AbstractOperation { /** + * @pure + * * @return Closure(T...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/DiffKeys.php b/src/Operation/DiffKeys.php index 4bed59a72..3346fd830 100644 --- a/src/Operation/DiffKeys.php +++ b/src/Operation/DiffKeys.php @@ -16,12 +16,16 @@ use function in_array; /** + * @immutable + * * @template TKey * @template T */ final class DiffKeys extends AbstractOperation { /** + * @pure + * * @return Closure(TKey...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Distinct.php b/src/Operation/Distinct.php index 98a26f16a..22edae549 100644 --- a/src/Operation/Distinct.php +++ b/src/Operation/Distinct.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Distinct extends AbstractOperation { /** + * @pure + * * @template U * * @return Closure(callable(U): Closure(U): bool): Closure(callable(T, TKey): U): Closure(Iterator): Generator diff --git a/src/Operation/Drop.php b/src/Operation/Drop.php index ec19199f9..de2f03dce 100644 --- a/src/Operation/Drop.php +++ b/src/Operation/Drop.php @@ -14,12 +14,16 @@ use LimitIterator; /** + * @immutable + * * @template TKey * @template T */ final class Drop extends AbstractOperation { /** + * @pure + * * @return Closure(int...): Closure(Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/DropWhile.php b/src/Operation/DropWhile.php index 752079be4..5873d5acb 100644 --- a/src/Operation/DropWhile.php +++ b/src/Operation/DropWhile.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class DropWhile extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey): bool ...): Closure (Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Dump.php b/src/Operation/Dump.php index 260466b0b..d3c44017b 100644 --- a/src/Operation/Dump.php +++ b/src/Operation/Dump.php @@ -15,6 +15,8 @@ use Symfony\Component\VarDumper\VarDumper; /** + * @immutable + * * @template TKey * @template T * @@ -23,6 +25,8 @@ final class Dump extends AbstractOperation { /** + * @pure + * * @return Closure(string): Closure(int): Closure(?Closure): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Duplicate.php b/src/Operation/Duplicate.php index dd08dc259..2eb1c5dee 100644 --- a/src/Operation/Duplicate.php +++ b/src/Operation/Duplicate.php @@ -16,12 +16,16 @@ use function in_array; /** + * @immutable + * * @template TKey * @template T */ final class Duplicate extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Every.php b/src/Operation/Every.php index 0278d2bb3..6494e73be 100644 --- a/src/Operation/Every.php +++ b/src/Operation/Every.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Every extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator...): bool): Closure(callable(T, TKey, Iterator...): bool): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Explode.php b/src/Operation/Explode.php index 1813fcd73..27a3d1979 100644 --- a/src/Operation/Explode.php +++ b/src/Operation/Explode.php @@ -15,12 +15,16 @@ use loophp\collection\Contract\Operation\Splitable; /** + * @immutable + * * @template TKey * @template T */ final class Explode extends AbstractOperation { /** + * @pure + * * @return Closure(T...): Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Falsy.php b/src/Operation/Falsy.php index 7b029f794..7af3edf29 100644 --- a/src/Operation/Falsy.php +++ b/src/Operation/Falsy.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Falsy extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Filter.php b/src/Operation/Filter.php index 55733871e..478130969 100644 --- a/src/Operation/Filter.php +++ b/src/Operation/Filter.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Filter extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T , TKey, Iterator): bool ...): Closure (Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/First.php b/src/Operation/First.php index 5cf5e632c..d03c6270c 100644 --- a/src/Operation/First.php +++ b/src/Operation/First.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class First extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/FlatMap.php b/src/Operation/FlatMap.php index 53e8c8a0e..54a89d73d 100644 --- a/src/Operation/FlatMap.php +++ b/src/Operation/FlatMap.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class FlatMap extends AbstractOperation { /** + * @pure + * * @template IKey * @template IValue * diff --git a/src/Operation/Flatten.php b/src/Operation/Flatten.php index d570f9d5b..ea8f52b41 100644 --- a/src/Operation/Flatten.php +++ b/src/Operation/Flatten.php @@ -15,12 +15,16 @@ use loophp\collection\Iterator\IterableIterator; /** + * @immutable + * * @template TKey * @template T */ final class Flatten extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Flip.php b/src/Operation/Flip.php index be543be69..036810016 100644 --- a/src/Operation/Flip.php +++ b/src/Operation/Flip.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Flip extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/FoldLeft.php b/src/Operation/FoldLeft.php index cca028b87..34238a764 100644 --- a/src/Operation/FoldLeft.php +++ b/src/Operation/FoldLeft.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class FoldLeft extends AbstractOperation { /** + * @pure + * * @return Closure(callable((T|null), T, TKey, Iterator):(T|null)): Closure(T): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/FoldLeft1.php b/src/Operation/FoldLeft1.php index 9f2b42905..88eced14c 100644 --- a/src/Operation/FoldLeft1.php +++ b/src/Operation/FoldLeft1.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class FoldLeft1 extends AbstractOperation { /** + * @pure + * * @return Closure(callable((T|null), T, TKey, Iterator):(T|null)): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/FoldRight.php b/src/Operation/FoldRight.php index 914784df7..1c66c68a6 100644 --- a/src/Operation/FoldRight.php +++ b/src/Operation/FoldRight.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class FoldRight extends AbstractOperation { /** + * @pure + * * @return Closure(callable((T|null), T, TKey, Iterator):(T|null)): Closure(T): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/FoldRight1.php b/src/Operation/FoldRight1.php index 0647e1db1..7eb3d840a 100644 --- a/src/Operation/FoldRight1.php +++ b/src/Operation/FoldRight1.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class FoldRight1 extends AbstractOperation { /** + * @pure + * * @return Closure(callable((T|null), T, TKey, Iterator): (T|null)):Closure (Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Forget.php b/src/Operation/Forget.php index 44fc0131e..adceb8da0 100644 --- a/src/Operation/Forget.php +++ b/src/Operation/Forget.php @@ -16,12 +16,16 @@ use function in_array; /** + * @immutable + * * @template TKey * @template T */ final class Forget extends AbstractOperation { /** + * @pure + * * @return Closure(TKey...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Frequency.php b/src/Operation/Frequency.php index 87a3e2605..8f76e3ec8 100644 --- a/src/Operation/Frequency.php +++ b/src/Operation/Frequency.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Frequency extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Get.php b/src/Operation/Get.php index 654721c29..64c6505a6 100644 --- a/src/Operation/Get.php +++ b/src/Operation/Get.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Get extends AbstractOperation { /** + * @pure + * * @return Closure(TKey): Closure (T|null): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Group.php b/src/Operation/Group.php index 63ca88887..b0906d4d9 100644 --- a/src/Operation/Group.php +++ b/src/Operation/Group.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Group extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/GroupBy.php b/src/Operation/GroupBy.php index 82af2a20f..40d342a0c 100644 --- a/src/Operation/GroupBy.php +++ b/src/Operation/GroupBy.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class GroupBy extends AbstractOperation { /** + * @pure + * * @return Closure((null | callable(TKey, T ): (TKey | null))):Closure (Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Has.php b/src/Operation/Has.php index 244297172..0116ddf7a 100644 --- a/src/Operation/Has.php +++ b/src/Operation/Has.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Has extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator): T ...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Head.php b/src/Operation/Head.php index 009d69338..3a5ccc6af 100644 --- a/src/Operation/Head.php +++ b/src/Operation/Head.php @@ -15,12 +15,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Head extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/IfThenElse.php b/src/Operation/IfThenElse.php index 797d2c380..a402acad8 100644 --- a/src/Operation/IfThenElse.php +++ b/src/Operation/IfThenElse.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class IfThenElse extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey): bool): Closure(callable(T, TKey): (T)): Closure(callable(T, TKey): (T)): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Implode.php b/src/Operation/Implode.php index 492d339cd..d913c93d3 100644 --- a/src/Operation/Implode.php +++ b/src/Operation/Implode.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Implode extends AbstractOperation { /** + * @pure + * * @return Closure(string): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Init.php b/src/Operation/Init.php index 1a4af4c7b..21d4ebc72 100644 --- a/src/Operation/Init.php +++ b/src/Operation/Init.php @@ -15,12 +15,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Init extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Inits.php b/src/Operation/Inits.php index dd276ad7e..b46c10b46 100644 --- a/src/Operation/Inits.php +++ b/src/Operation/Inits.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Inits extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Intersect.php b/src/Operation/Intersect.php index d80fa8a8f..003631214 100644 --- a/src/Operation/Intersect.php +++ b/src/Operation/Intersect.php @@ -16,12 +16,16 @@ use function in_array; /** + * @immutable + * * @template TKey * @template T */ final class Intersect extends AbstractOperation { /** + * @pure + * * @return Closure(T...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/IntersectKeys.php b/src/Operation/IntersectKeys.php index 2eb51be6b..f8563723b 100644 --- a/src/Operation/IntersectKeys.php +++ b/src/Operation/IntersectKeys.php @@ -16,12 +16,16 @@ use function in_array; /** + * @immutable + * * @template TKey * @template T */ final class IntersectKeys extends AbstractOperation { /** + * @pure + * * @return Closure(TKey...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Intersperse.php b/src/Operation/Intersperse.php index 008cf09b3..3ce2f259b 100644 --- a/src/Operation/Intersperse.php +++ b/src/Operation/Intersperse.php @@ -15,12 +15,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Intersperse extends AbstractOperation { /** + * @pure + * * @return Closure(T): Closure(int): Closure(int): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Key.php b/src/Operation/Key.php index f9d24e281..7289e274f 100644 --- a/src/Operation/Key.php +++ b/src/Operation/Key.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Key extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Keys.php b/src/Operation/Keys.php index d25614b71..ba6565fa5 100644 --- a/src/Operation/Keys.php +++ b/src/Operation/Keys.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Keys extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Last.php b/src/Operation/Last.php index c31e48909..63e81333e 100644 --- a/src/Operation/Last.php +++ b/src/Operation/Last.php @@ -15,12 +15,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Last extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Limit.php b/src/Operation/Limit.php index d58fb47c7..1f326a7ee 100644 --- a/src/Operation/Limit.php +++ b/src/Operation/Limit.php @@ -14,6 +14,8 @@ use LimitIterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Limit extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(int): Closure(Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/Lines.php b/src/Operation/Lines.php index 085479309..d6f58ea76 100644 --- a/src/Operation/Lines.php +++ b/src/Operation/Lines.php @@ -16,12 +16,16 @@ use const PHP_EOL; /** + * @immutable + * * @template TKey * @template T */ final class Lines extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Map.php b/src/Operation/Map.php index 8131ccdd1..6aab70ec2 100644 --- a/src/Operation/Map.php +++ b/src/Operation/Map.php @@ -18,6 +18,8 @@ use const E_USER_DEPRECATED; /** + * @immutable + * * @template TKey * @template T * @@ -26,6 +28,8 @@ final class Map extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator): T ...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/MapN.php b/src/Operation/MapN.php index fcc74d8ee..6779f01a5 100644 --- a/src/Operation/MapN.php +++ b/src/Operation/MapN.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class MapN extends AbstractOperation { /** + * @pure + * * @return Closure(callable(mixed, mixed, Iterator): mixed ...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/MatchOne.php b/src/Operation/MatchOne.php index e321f212c..8bf0ee8cf 100644 --- a/src/Operation/MatchOne.php +++ b/src/Operation/MatchOne.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class MatchOne extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator): T): Closure(callable(T, TKey, Iterator): bool): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Matching.php b/src/Operation/Matching.php index 4f77456a4..1633cef9a 100644 --- a/src/Operation/Matching.php +++ b/src/Operation/Matching.php @@ -17,6 +17,8 @@ use loophp\collection\Contract\Operation\Sortable; /** + * @immutable + * * @template TKey * @template T * @@ -25,6 +27,8 @@ final class Matching extends AbstractOperation { /** + * @pure + * * @return Closure(Criteria): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Merge.php b/src/Operation/Merge.php index 123dedbe8..2ddc50ce7 100644 --- a/src/Operation/Merge.php +++ b/src/Operation/Merge.php @@ -14,12 +14,16 @@ use loophp\collection\Iterator\MultipleIterableIterator; /** + * @immutable + * * @template TKey * @template T */ final class Merge extends AbstractOperation { /** + * @pure + * * @return Closure(iterable...): Closure(Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/Normalize.php b/src/Operation/Normalize.php index 36094cfd1..2c0f994ec 100644 --- a/src/Operation/Normalize.php +++ b/src/Operation/Normalize.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Normalize extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Nth.php b/src/Operation/Nth.php index 8b5f4a904..ed0b8f96d 100644 --- a/src/Operation/Nth.php +++ b/src/Operation/Nth.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Nth extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(int): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Nullsy.php b/src/Operation/Nullsy.php index 825f027a0..e0723dfed 100644 --- a/src/Operation/Nullsy.php +++ b/src/Operation/Nullsy.php @@ -16,6 +16,8 @@ use function in_array; /** + * @immutable + * * @template TKey * @template T */ @@ -27,6 +29,8 @@ final class Nullsy extends AbstractOperation public const VALUES = [null, [], 0, false, '']; /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Pack.php b/src/Operation/Pack.php index 24cd0a4f2..982195aee 100644 --- a/src/Operation/Pack.php +++ b/src/Operation/Pack.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Pack extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Pad.php b/src/Operation/Pad.php index 270e2b99f..7f305e7b4 100644 --- a/src/Operation/Pad.php +++ b/src/Operation/Pad.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Pad extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(T): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Pair.php b/src/Operation/Pair.php index 4952772d9..576703d23 100644 --- a/src/Operation/Pair.php +++ b/src/Operation/Pair.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Pair extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Partition.php b/src/Operation/Partition.php index 248711157..63f3d694c 100644 --- a/src/Operation/Partition.php +++ b/src/Operation/Partition.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Partition extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator):bool...): Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Permutate.php b/src/Operation/Permutate.php index 95596762e..405266314 100644 --- a/src/Operation/Permutate.php +++ b/src/Operation/Permutate.php @@ -14,11 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Permutate extends AbstractOperation { + /** + * @pure + */ public function __invoke(): Closure { $getPermutations = diff --git a/src/Operation/Pipe.php b/src/Operation/Pipe.php index 1a6fc89c6..733d1f3d8 100644 --- a/src/Operation/Pipe.php +++ b/src/Operation/Pipe.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Pipe extends AbstractOperation { /** + * @pure + * * @return Closure(...callable(Iterator):Generator):Closure(Iterator):Iterator */ public function __invoke(): Closure diff --git a/src/Operation/Pluck.php b/src/Operation/Pluck.php index d37124fb5..5909b0d13 100644 --- a/src/Operation/Pluck.php +++ b/src/Operation/Pluck.php @@ -23,6 +23,8 @@ use function is_object; /** + * @immutable + * * @template TKey * @template T * @@ -31,6 +33,8 @@ final class Pluck extends AbstractOperation { /** + * @pure + * * @return Closure(T):Closure(T):Closure(Iterator):Generator, mixed, void> */ public function __invoke(): Closure diff --git a/src/Operation/Prepend.php b/src/Operation/Prepend.php index e085e5cbb..a2fe58633 100644 --- a/src/Operation/Prepend.php +++ b/src/Operation/Prepend.php @@ -14,12 +14,16 @@ use loophp\collection\Iterator\MultipleIterableIterator; /** + * @immutable + * * @template TKey * @template T */ final class Prepend extends AbstractOperation { /** + * @pure + * * @return Closure(T...): Closure(Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/Product.php b/src/Operation/Product.php index 9a87aae7c..943c31c75 100644 --- a/src/Operation/Product.php +++ b/src/Operation/Product.php @@ -16,11 +16,16 @@ use function count; /** + * @immutable + * * @template TKey * @template T */ final class Product extends AbstractOperation { + /** + * @pure + */ public function __invoke(): Closure { return diff --git a/src/Operation/RSample.php b/src/Operation/RSample.php index 464223848..f0f00328a 100644 --- a/src/Operation/RSample.php +++ b/src/Operation/RSample.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class RSample extends AbstractOperation { /** + * @pure + * * @return Closure(float): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Random.php b/src/Operation/Random.php index a5e96a6b1..2c620968d 100644 --- a/src/Operation/Random.php +++ b/src/Operation/Random.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Random extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(int): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Range.php b/src/Operation/Range.php index 1382947f0..8ce8f13b5 100644 --- a/src/Operation/Range.php +++ b/src/Operation/Range.php @@ -16,6 +16,8 @@ use const INF; /** + * @immutable + * * @template TKey * @template T * @@ -24,6 +26,8 @@ final class Range extends AbstractOperation { /** + * @pure + * * @return Closure(float = default):Closure (float=): Closure(float=): Closure(null|Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Reduction.php b/src/Operation/Reduction.php index 349035c98..1a9215b44 100644 --- a/src/Operation/Reduction.php +++ b/src/Operation/Reduction.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Reduction extends AbstractOperation { /** + * @pure + * * @return Closure(callable((T|null), T, TKey, Iterator): (T|null)):Closure (T|null): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Reverse.php b/src/Operation/Reverse.php index 987171a2f..27e4dcc32 100644 --- a/src/Operation/Reverse.php +++ b/src/Operation/Reverse.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @todo Remove the Wrap and Unwrap operations * @todo They are only needed when: Collection::empty()->reverse() * @todo Most probably that the FoldLeft operation needs an update. @@ -24,6 +26,8 @@ final class Reverse extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Scale.php b/src/Operation/Scale.php index ba37cdfcd..ecf487466 100644 --- a/src/Operation/Scale.php +++ b/src/Operation/Scale.php @@ -16,6 +16,8 @@ use const INF; /** + * @immutable + * * @template TKey * @template T * @@ -24,6 +26,8 @@ final class Scale extends AbstractOperation { /** + * @pure + * * @return Closure(float): Closure(float): Closure(float): Closure(float): Closure(float): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/ScanLeft.php b/src/Operation/ScanLeft.php index 5f1689fab..b74c6f2b7 100644 --- a/src/Operation/ScanLeft.php +++ b/src/Operation/ScanLeft.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class ScanLeft extends AbstractOperation { /** + * @pure + * * @return Closure(callable((T|null), T, TKey, Iterator): (T|null)):Closure (T|null): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/ScanLeft1.php b/src/Operation/ScanLeft1.php index 1f03e5d0c..5c2bafddd 100644 --- a/src/Operation/ScanLeft1.php +++ b/src/Operation/ScanLeft1.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class ScanLeft1 extends AbstractOperation { /** + * @pure + * * @return Closure(callable((T|null), T, TKey, Iterator): (T|null)):Closure (Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/ScanRight.php b/src/Operation/ScanRight.php index 3131d3685..b5d4c576c 100644 --- a/src/Operation/ScanRight.php +++ b/src/Operation/ScanRight.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class ScanRight extends AbstractOperation { /** + * @pure + * * @return Closure(callable((T|null), T, TKey, Iterator): (T|null)):Closure (T|null): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/ScanRight1.php b/src/Operation/ScanRight1.php index bb7d89540..15d748ddb 100644 --- a/src/Operation/ScanRight1.php +++ b/src/Operation/ScanRight1.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class ScanRight1 extends AbstractOperation { /** + * @pure + * * @return Closure(callable((T|null), T, TKey, Iterator): (T|null)):Closure (Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Shuffle.php b/src/Operation/Shuffle.php index d89e80b64..155c96606 100644 --- a/src/Operation/Shuffle.php +++ b/src/Operation/Shuffle.php @@ -14,12 +14,16 @@ use loophp\collection\Iterator\RandomIterator; /** + * @immutable + * * @template TKey * @template T */ final class Shuffle extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/Since.php b/src/Operation/Since.php index 96e13dc69..2fd216b80 100644 --- a/src/Operation/Since.php +++ b/src/Operation/Since.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Since extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator):bool ...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Slice.php b/src/Operation/Slice.php index b2e52438e..32b48fb12 100644 --- a/src/Operation/Slice.php +++ b/src/Operation/Slice.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Slice extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(int=): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Sort.php b/src/Operation/Sort.php index b4dea58f8..b50ee7081 100644 --- a/src/Operation/Sort.php +++ b/src/Operation/Sort.php @@ -17,6 +17,8 @@ use loophp\collection\Contract\Operation; /** + * @immutable + * * @template TKey * @template T * @@ -25,6 +27,8 @@ final class Sort extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(callable(T|TKey, T|TKey): int): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Span.php b/src/Operation/Span.php index ac304b827..a31cfd11d 100644 --- a/src/Operation/Span.php +++ b/src/Operation/Span.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Span extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator): bool):Closure (Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Split.php b/src/Operation/Split.php index af5ae0f14..168f06eb3 100644 --- a/src/Operation/Split.php +++ b/src/Operation/Split.php @@ -15,6 +15,8 @@ use loophp\collection\Contract\Operation\Splitable; /** + * @immutable + * * @template TKey * @template T * @@ -23,6 +25,8 @@ final class Split extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure((callable(T, TKey): bool)...): Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Strict.php b/src/Operation/Strict.php index 255fbb9e0..aaa39d6f9 100644 --- a/src/Operation/Strict.php +++ b/src/Operation/Strict.php @@ -14,12 +14,16 @@ use loophp\collection\Iterator\TypedIterator; /** + * @immutable + * * @template TKey * @template T */ final class Strict extends AbstractOperation { /** + * @pure + * * @return Closure(null|callable(mixed): string): Closure(Iterator): Iterator */ public function __invoke(): Closure diff --git a/src/Operation/Tail.php b/src/Operation/Tail.php index ec0d57521..cdb768fda 100644 --- a/src/Operation/Tail.php +++ b/src/Operation/Tail.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Tail extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Tails.php b/src/Operation/Tails.php index 5d96d5c0b..275141443 100644 --- a/src/Operation/Tails.php +++ b/src/Operation/Tails.php @@ -15,12 +15,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Tails extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator, mixed, void> */ public function __invoke(): Closure diff --git a/src/Operation/TakeWhile.php b/src/Operation/TakeWhile.php index b63f8fc65..27dc02278 100644 --- a/src/Operation/TakeWhile.php +++ b/src/Operation/TakeWhile.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class TakeWhile extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator): bool):Closure (Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Times.php b/src/Operation/Times.php index 39fcb4018..1cc2e3ae1 100644 --- a/src/Operation/Times.php +++ b/src/Operation/Times.php @@ -15,6 +15,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -23,6 +25,8 @@ final class Times extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(null|callable(int): (int|T)): Closure(null|Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Transpose.php b/src/Operation/Transpose.php index 15fb787e5..4db72928e 100644 --- a/src/Operation/Transpose.php +++ b/src/Operation/Transpose.php @@ -16,12 +16,16 @@ use MultipleIterator; /** + * @immutable + * * @template TKey * @template T */ final class Transpose extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Truthy.php b/src/Operation/Truthy.php index 2c34a6d33..20be6835b 100644 --- a/src/Operation/Truthy.php +++ b/src/Operation/Truthy.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Truthy extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Unfold.php b/src/Operation/Unfold.php index 62df49d96..79b3f599a 100644 --- a/src/Operation/Unfold.php +++ b/src/Operation/Unfold.php @@ -13,6 +13,8 @@ use Generator; /** + * @immutable + * * @template TKey * @template T * @@ -21,6 +23,8 @@ final class Unfold extends AbstractOperation { /** + * @pure + * * @return Closure(T...): Closure(callable(mixed|T...): (mixed|array)): Closure(): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Unlines.php b/src/Operation/Unlines.php index 432cd974a..8f7195124 100644 --- a/src/Operation/Unlines.php +++ b/src/Operation/Unlines.php @@ -16,12 +16,16 @@ use const PHP_EOL; /** + * @immutable + * * @template TKey * @template T */ final class Unlines extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Unpack.php b/src/Operation/Unpack.php index 8394ee395..1f3e0911d 100644 --- a/src/Operation/Unpack.php +++ b/src/Operation/Unpack.php @@ -15,6 +15,8 @@ use loophp\collection\Iterator\IterableIterator; /** + * @immutable + * * @template NewTKey * @template NewT * @@ -24,6 +26,8 @@ final class Unpack extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Unpair.php b/src/Operation/Unpair.php index 5fa1e92d3..077f3c6f3 100644 --- a/src/Operation/Unpair.php +++ b/src/Operation/Unpair.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Unpair extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Until.php b/src/Operation/Until.php index 5c8ab0f37..017dffbeb 100644 --- a/src/Operation/Until.php +++ b/src/Operation/Until.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class Until extends AbstractOperation { /** + * @pure + * * @return Closure(callable(T, TKey, Iterator): bool ...): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Unwindow.php b/src/Operation/Unwindow.php index 69a13ebf4..69088338b 100644 --- a/src/Operation/Unwindow.php +++ b/src/Operation/Unwindow.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Unwindow extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator>): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Unwords.php b/src/Operation/Unwords.php index 6bc535e3e..80575b566 100644 --- a/src/Operation/Unwords.php +++ b/src/Operation/Unwords.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Unwords extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Unwrap.php b/src/Operation/Unwrap.php index 9f276840b..354c161ef 100644 --- a/src/Operation/Unwrap.php +++ b/src/Operation/Unwrap.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Unwrap extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Unzip.php b/src/Operation/Unzip.php index afe58346b..4c935873e 100644 --- a/src/Operation/Unzip.php +++ b/src/Operation/Unzip.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Unzip extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator>): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/When.php b/src/Operation/When.php index 8df9c62eb..cd193ebf0 100644 --- a/src/Operation/When.php +++ b/src/Operation/When.php @@ -14,6 +14,8 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T * @@ -22,6 +24,8 @@ final class When extends AbstractOperation { /** + * @pure + * * @return Closure(callable(Iterator): bool): Closure(callable(Iterator): iterable): Closure(callable(Iterator): iterable): Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Window.php b/src/Operation/Window.php index 5e262336f..ff16524b9 100644 --- a/src/Operation/Window.php +++ b/src/Operation/Window.php @@ -16,12 +16,16 @@ use function array_slice; /** + * @immutable + * * @template TKey * @template T */ final class Window extends AbstractOperation { /** + * @pure + * * @return Closure(int): Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Words.php b/src/Operation/Words.php index b92ed6f36..1b35d3608 100644 --- a/src/Operation/Words.php +++ b/src/Operation/Words.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Words extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator */ public function __invoke(): Closure diff --git a/src/Operation/Wrap.php b/src/Operation/Wrap.php index e9999db32..af349be68 100644 --- a/src/Operation/Wrap.php +++ b/src/Operation/Wrap.php @@ -14,12 +14,16 @@ use Iterator; /** + * @immutable + * * @template TKey * @template T */ final class Wrap extends AbstractOperation { /** + * @pure + * * @return Closure(Iterator): Generator> */ public function __invoke(): Closure diff --git a/src/Operation/Zip.php b/src/Operation/Zip.php index 2f93cc1be..c49172f9a 100644 --- a/src/Operation/Zip.php +++ b/src/Operation/Zip.php @@ -15,6 +15,8 @@ use MultipleIterator; /** + * @immutable + * * @template TKey * @template T * @@ -23,6 +25,8 @@ final class Zip extends AbstractOperation { /** + * @pure + * * @return Closure(iterable...): Closure(Iterator): Iterator, list> */ public function __invoke(): Closure From 64b0eb9af82c988f7bbe08a027d82cb531de05d1 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Mon, 5 Jul 2021 12:12:52 +0100 Subject: [PATCH 3/4] Fixer --- src/Contract/Operation.php | 8 ++++++-- src/Operation/AbstractOperation.php | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Contract/Operation.php b/src/Contract/Operation.php index 4397fc6b1..7e7a5b95b 100644 --- a/src/Contract/Operation.php +++ b/src/Contract/Operation.php @@ -14,9 +14,13 @@ /** @immutable */ interface Operation { - /** @pure */ + /** + * @pure + */ public function __invoke(): Closure; - /** @pure */ + /** + * @pure + */ public static function of(): Closure; } diff --git a/src/Operation/AbstractOperation.php b/src/Operation/AbstractOperation.php index c09e66fcb..2a4253419 100644 --- a/src/Operation/AbstractOperation.php +++ b/src/Operation/AbstractOperation.php @@ -17,12 +17,16 @@ */ abstract class AbstractOperation implements Operation { - /** @pure */ + /** + * @pure + */ final public function __construct() { } - /** @pure */ + /** + * @pure + */ public static function of(): Closure { return (new static())->__invoke(); From 43be1fb44456ad15f985fdb9b2a2f28e246dcc84 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Mon, 5 Jul 2021 12:19:37 +0100 Subject: [PATCH 4/4] No need for this --- src/Contract/Operation/Squashable.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Contract/Operation/Squashable.php b/src/Contract/Operation/Squashable.php index d61678a5a..cb0804b37 100644 --- a/src/Contract/Operation/Squashable.php +++ b/src/Contract/Operation/Squashable.php @@ -12,8 +12,6 @@ use loophp\collection\Contract\Collection; /** - * @immutable - * * @template TKey * @template T */