Skip to content

Commit

Permalink
refactor: Minor optimizations here and there.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Apr 10, 2022
1 parent e9c4460 commit f08d88e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
18 changes: 6 additions & 12 deletions src/Operation/Has.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,17 @@ public function __invoke(): Closure
*
* @return Closure(iterable<TKey, T>): Generator<TKey, bool>
*/
static function (callable ...$callbacks): Closure {
/** @var Closure(iterable<TKey, T>): Generator<TKey, bool> $matchOne */
$matchOne = (new MatchOne())()(static fn (): bool => true)(
...array_map(
static fn (callable $callback): callable =>
static fn (callable ...$callbacks): Closure => (new MatchOne())()(static fn (): bool => true)(
...array_map(
static fn (callable $callback): callable =>
/**
* @param T $value
* @param TKey $key
* @param iterable<TKey, T> $iterable
*/
static fn ($value, $key, iterable $iterable): bool => $callback($value, $key, $iterable) === $value,
$callbacks
)
);

// Point free style.
return $matchOne;
};
$callbacks
)
);
}
}
5 changes: 1 addition & 4 deletions src/Operation/IntersectKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ public function __invoke(): Closure
* @return Closure(iterable<TKey, T>): Generator<TKey, T>
*/
static function (...$keys): Closure {
$filter = (new Filter())()(
return (new Filter())()(
/**
* @param T $value
* @param TKey $key
*/
static fn ($value, $key): bool => in_array($key, $keys, true)
);

// Point free style.
return $filter;
};
}
}

0 comments on commit f08d88e

Please sign in to comment.