Skip to content

Commit

Permalink
refactor: Minor optimization in Unwindow operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 3, 2021
1 parent ae36094 commit 710c52f
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/Operation/Unwindow.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Closure;
use Generator;
use Iterator;
use loophp\collection\Iterator\IterableIterator;

/**
* @psalm-template TKey
Expand All @@ -24,26 +23,16 @@ public function __invoke(): Closure
/** @psalm-var Closure(Iterator<TKey, list<T>>): Generator<TKey, T> $unwindow */
$unwindow = Map::of()(
/**
* @psalm-param iterable<TKey, list<T>> $value
*/
static fn (iterable $iterable): Iterator => new IterableIterator($iterable),
/**
* @psalm-param Iterator<TKey, list<T>> $iterator
*
* @psalm-return Generator<TKey, T>
*/
static function (Iterator $iterator): Generator {
/** @psalm-var Closure(Iterator<TKey, list<T>>): Generator<TKey, T> $last */
$last = Last::of();

return $last($iterator);
},
/**
* @psalm-param Generator<TKey, T> $value
* @psalm-param iterable<TKey, list<T>> $iterable
*
* @psalm-return T
*/
static fn (Generator $value) => $value->current()
static function (iterable $iterable) {
foreach ($iterable as $value) {
}

return $value;
}
);

// Point free style.
Expand Down

0 comments on commit 710c52f

Please sign in to comment.