Skip to content

Commit

Permalink
Update Reverse operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jul 6, 2020
1 parent 0bd0e42 commit a9b6c9a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Operation/Reverse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
use Generator;
use loophp\collection\Contract\Operation;
use loophp\collection\Transformation\All;
use loophp\collection\Transformation\Run;
use loophp\collection\Transformation\Transform;

final class Reverse extends AbstractOperation implements Operation
{
public function __invoke(): Closure
{
return static function (iterable $collection): Generator {
$all = (new All())($collection);
$all = (new Transform(new All()))((new Run(new Wrap()))($collection));

for (end($all); null !== ($key = key($all)); prev($all)) {
yield $key => current($all);
for (end($all); null !== key($all); prev($all)) {
$item = current($all);

yield key($item) => current($item);
}
};
}
Expand Down

0 comments on commit a9b6c9a

Please sign in to comment.