Skip to content

Commit

Permalink
refactor: Update Drop operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jan 2, 2021
1 parent 7957e26 commit 3d4786b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 8 additions & 0 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,14 @@ public function it_can_do_the_cartesian_product(): void
$this::fromIterable(range('A', 'C'))
->product([1, 2])
->shouldIterateAs([0 => ['A', 1], 1 => ['A', 2], 2 => ['B', 1], 3 => ['B', 2], 4 => ['C', 1], 5 => ['C', 2]]);

$string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
$stream = fopen('data://text/plain,' . $string, 'rb');

$this::fromResource($stream)
->drop(1)
->count()
->shouldReturn(55);
}

public function it_can_drop(): void
Expand Down
5 changes: 0 additions & 5 deletions src/Operation/Drop.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace loophp\collection\Operation;

use Closure;
use EmptyIterator;
use Iterator;
use LimitIterator;

Expand All @@ -32,10 +31,6 @@ public function __invoke(): Closure
* @psalm-return Iterator<TKey, T>
*/
static function (Iterator $iterator) use ($offsets): Iterator {
if (false === $iterator->valid()) {
return new EmptyIterator();
}

return new LimitIterator($iterator, array_sum($offsets));
};
}
Expand Down

0 comments on commit 3d4786b

Please sign in to comment.