Skip to content

Commit

Permalink
Update Slice operation
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Aug 27, 2020
1 parent 8e25055 commit fc5baa6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public function skip(int ...$counts): CollectionInterface
return $this->run(new Skip(...$counts));
}

public function slice(int $offset, ?int $length = null): CollectionInterface
public function slice(int $offset, int $length = -1): CollectionInterface
{
return $this->run(new Slice($offset, $length));
}
Expand Down
4 changes: 1 addition & 3 deletions src/Contract/Operation/Sliceable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ interface Sliceable
/**
* Get a slice of a collection.
*
* @param ?int $length
*
* @psalm-return \loophp\collection\Contract\Collection<TKey, T>
*/
public function slice(int $offset, ?int $length = null): Collection;
public function slice(int $offset, int $length = -1): Collection;
}
6 changes: 3 additions & 3 deletions src/Operation/Slice.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
final class Slice extends AbstractOperation implements Operation
{
public function __construct(int $offset, ?int $length = null)
public function __construct(int $offset, int $length = -1)
{
$this->storage = [
'offset' => $offset,
Expand All @@ -33,10 +33,10 @@ public function __invoke(): Closure
*
* @psalm-return Generator<TKey, T>
*/
static function (Iterator $iterator, int $offset, ?int $length): Generator {
static function (Iterator $iterator, int $offset, int $length): Generator {
$skip = (new Run(new Skip($offset)))($iterator);

if (null === $length) {
if (-1 === $length) {
return yield from $skip;
}

Expand Down

0 comments on commit fc5baa6

Please sign in to comment.