Skip to content

Commit

Permalink
refactor: Factorize closures.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 27, 2020
1 parent 4c4b77d commit 739e9c6
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/Operation/Truthy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ final class Truthy extends AbstractOperation
*/
public function __invoke(): Closure
{
$matchCallback =
/**
* @param mixed $value
* @psalm-param T $value
*/
static fn ($value): bool => !(bool) $value;

$mapCallback =
$callback =
/**
* @param mixed $value
* @psalm-param T $value
Expand All @@ -36,8 +29,8 @@ public function __invoke(): Closure

/** @psalm-var Closure(Iterator<TKey, T>): Generator<int, bool> $pipe */
$pipe = Pipe::of()(
MatchOne::of()(static fn () => true)($matchCallback),
Map::of()($mapCallback),
MatchOne::of()(static fn () => true)($callback),
Map::of()($callback),
);

// Point free style.
Expand Down

0 comments on commit 739e9c6

Please sign in to comment.