diff --git a/src/Operation/Distinct.php b/src/Operation/Distinct.php index 76e09d853..278b4a5fb 100644 --- a/src/Operation/Distinct.php +++ b/src/Operation/Distinct.php @@ -52,16 +52,20 @@ static function (callable $accessorCallback) use ($comparatorCallback): Closure * @param TKey $key */ static function ($value, $key) use ($comparatorCallback, $accessorCallback, $stack): bool { - $matchWhenNot = static fn (): bool => true; $matcher = /** * @param array{0: TKey, 1: T} $item */ - static fn (array $item): bool => $comparatorCallback($accessorCallback($value, $key))($accessorCallback($item[1], $item[0])); + static fn (array $item): bool => !$comparatorCallback($accessorCallback($value, $key))($accessorCallback($item[1], $item[0])); - $matchFalse = (new MatchOne())()($matchWhenNot)($matcher)($stack); + $every = (new Every())()( + /** + * @param array{0: TKey, 1: T} $keyValuePair + */ + static fn (int $index, array $keyValuePair): bool => $matcher($keyValuePair) + )($stack); - if ($matchFalse->current()) { + if (false === $every->current()) { return false; } diff --git a/src/Operation/Falsy.php b/src/Operation/Falsy.php index f0c95608b..9fce4aed1 100644 --- a/src/Operation/Falsy.php +++ b/src/Operation/Falsy.php @@ -25,31 +25,15 @@ final class Falsy extends AbstractOperation */ public function __invoke(): Closure { - $matchWhenNot = static fn (): bool => true; - $matcher = + /** @var Closure(iterable): Generator $every */ + $every = (new Every())()( /** - * @param bool $value + * @param T $value */ - static fn (bool $value): bool => $value; - - /** @var Closure(iterable): Generator $pipe */ - $pipe = (new Pipe())()( - (new Map())()( - /** - * @param T $value - */ - static fn ($value): bool => (bool) $value - ), - (new MatchOne())()($matchWhenNot)($matcher), - (new Map())()( - /** - * @param bool $value - */ - static fn (bool $value): bool => !$value - ), + static fn (int $index, $value): bool => !(bool) $value ); // Point free style. - return $pipe; + return $every; } } diff --git a/src/Operation/MatchOne.php b/src/Operation/MatchOne.php index 797314b01..f40322189 100644 --- a/src/Operation/MatchOne.php +++ b/src/Operation/MatchOne.php @@ -54,7 +54,6 @@ static function (callable ...$callbacks) use ($matchers): Closure { */ static fn (int $index, $value, $key, iterable $iterable): bool => $callback($value, $key, $iterable) !== $matcher($value, $key, $iterable) ), - (new Head())(), (new Map())()( static fn (bool $i): bool => !$i ) diff --git a/src/Operation/Nullsy.php b/src/Operation/Nullsy.php index 83c33838f..19a59ce66 100644 --- a/src/Operation/Nullsy.php +++ b/src/Operation/Nullsy.php @@ -34,31 +34,15 @@ final class Nullsy extends AbstractOperation */ public function __invoke(): Closure { - $matchWhenNot = static fn (): bool => false; - $matcher = + /** @var Closure(iterable): Generator $every */ + $every = (new Every())()( /** - * @param bool $value + * @param T $value */ - static fn (bool $value): bool => in_array($value, self::VALUES, true); - - /** @var Closure(iterable): Generator $pipe */ - $pipe = (new Pipe())()( - (new Map())()( - /** - * @param T $value - */ - static fn ($value): bool => (bool) $value - ), - (new MatchOne())()($matchWhenNot)($matcher), - (new Map())()( - /** - * @param bool $value - */ - static fn (bool $value): bool => !$value - ), + static fn (int $index, $value): bool => in_array((bool) $value, self::VALUES, true) ); // Point free style. - return $pipe; + return $every; } } diff --git a/src/Operation/Truthy.php b/src/Operation/Truthy.php index bf2985492..9fd649159 100644 --- a/src/Operation/Truthy.php +++ b/src/Operation/Truthy.php @@ -25,26 +25,15 @@ final class Truthy extends AbstractOperation */ public function __invoke(): Closure { - $matchWhenNot = static fn (): bool => true; - $matcher = + /** @var Closure(iterable): Generator $every */ + $every = (new Every())()( /** - * @param bool $value + * @param T $value */ - static fn (bool $value): bool => !$value; - - /** @var Closure(iterable): Generator $pipe */ - $pipe = (new Pipe())()( - (new Map())()( - /** - * @param T $value - */ - static fn ($value): bool => (bool) $value - ), - (new MatchOne())()($matchWhenNot)($matcher), - (new Map())()($matcher), + static fn (int $index, $value): bool => (bool) $value ); // Point free style. - return $pipe; + return $every; } }