Skip to content

Commit

Permalink
refactor: Update Head and First operations.
Browse files Browse the repository at this point in the history
Signed-off-by: Pol Dellaiera <pol.dellaiera@protonmail.com>
  • Loading branch information
drupol committed Nov 6, 2020
1 parent 8b848bb commit eb792af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Operation/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static function ($column): Closure {
$pipe = Pipe::of()(
Transpose::of(),
Filter::of()($filterCallbackBuilder($column)),
First::of(),
Head::of(),
Unwrap::of()
);

Expand Down
16 changes: 4 additions & 12 deletions src/Operation/First.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@ final class First extends AbstractOperation
*/
public function __invoke(): Closure
{
return
/**
* @psalm-param Iterator<TKey, T> $iterator
*
* @psalm-return Generator<TKey, T>
*/
static function (Iterator $iterator): Generator {
if (!$iterator->valid()) {
return yield from [];
}
/** @psalm-var Closure(Iterator<TKey, T>): Generator<TKey, T> $head */
$head = Head::of();

return yield $iterator->key() => $iterator->current();
};
// Point free style.
return $head;
}
}
16 changes: 12 additions & 4 deletions src/Operation/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ final class Head extends AbstractOperation
*/
public function __invoke(): Closure
{
/** @psalm-var Closure(Iterator<TKey, T>): Generator<TKey, T> $first */
$first = First::of();
return
/**
* @psalm-param Iterator<TKey, T> $iterator
*
* @psalm-return Generator<TKey, T>
*/
static function (Iterator $iterator): Generator {
if (!$iterator->valid()) {
return yield from [];
}

// Point free style.
return $first;
return yield $iterator->key() => $iterator->current();
};
}
}

0 comments on commit eb792af

Please sign in to comment.