Skip to content

Commit

Permalink
Leverage the variadic arguments wherever we can.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed May 29, 2020
1 parent ff1f702 commit 978323e
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function all(): array
*/
public function append(...$items): BaseInterface
{
return $this->run(new Append($items));
return $this->run(new Append(...$items));
}

/**
Expand Down Expand Up @@ -118,7 +118,7 @@ public function combinate(?int $length = null): BaseInterface
*/
public function combine(...$keys): BaseInterface
{
return $this->run(new Combine($keys));
return $this->run(new Combine(...$keys));
}

/**
Expand Down Expand Up @@ -222,7 +222,7 @@ public function foldRight(callable $callback, $initial = null)
*/
public function forget(...$keys): BaseInterface
{
return $this->run(new Forget($keys));
return $this->run(new Forget(...$keys));
}

/**
Expand Down Expand Up @@ -292,9 +292,9 @@ public function map(callable ...$callbacks): BaseInterface
/**
* {@inheritdoc}
*/
public function merge(...$sources): BaseInterface
public function merge(iterable ...$sources): BaseInterface
{
return $this->run(new Merge($sources));
return $this->run(new Merge(...$sources));
}

/**
Expand All @@ -318,7 +318,7 @@ public function nth(int $step, int $offset = 0): BaseInterface
*/
public function only(...$keys): BaseInterface
{
return $this->run(new Only($keys));
return $this->run(new Only(...$keys));
}

/**
Expand Down Expand Up @@ -491,6 +491,6 @@ public static function with($data = [], ...$parameters): CollectionInterface
*/
public function zip(iterable ...$iterables): BaseInterface
{
return $this->run(new Zip($iterables));
return $this->run(new Zip(...$iterables));
}
}
2 changes: 1 addition & 1 deletion src/Contract/Mergeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ interface Mergeable
*
* @return \loophp\collection\Contract\Collection<mixed>
*/
public function merge(...$sources): Base;
public function merge(iterable ...$sources): Base;
}
2 changes: 0 additions & 2 deletions src/Operation/Append.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public function on(iterable $collection): Closure
yield $value;
}

[$items] = $items;

foreach ($items as $item) {
yield $item;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Operation/Combine.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public function on(iterable $collection): Closure
$keys = $this->keys;

return static function () use ($keys, $collection): Generator {
[$keys] = $keys;

$original = new IterableIterator($collection);
$keysIterator = new ArrayIterator($keys);

Expand Down
1 change: 0 additions & 1 deletion src/Operation/Forget.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function on(iterable $collection): Closure
$keys = $this->keys;

return static function () use ($keys, $collection): Generator {
[$keys] = $keys;
$keys = array_flip($keys);

foreach ($collection as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(iterable ...$sources)
*/
public function on(iterable $collection): Closure
{
[$sources] = $this->sources;
$sources = $this->sources;

return static function () use ($sources, $collection): Generator {
foreach ($collection as $value) {
Expand Down
2 changes: 0 additions & 2 deletions src/Operation/Only.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public function on(iterable $collection): Closure
$keys = $this->keys;

return static function () use ($keys, $collection): Generator {
[$keys] = $keys;

if ([] === $keys) {
return yield from $collection;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(iterable ...$iterables)
*/
public function on(iterable $collection): Closure
{
[$iterables] = $this->iterables;
$iterables = $this->iterables;

return static function () use ($iterables, $collection): Generator {
$getIteratorCallback = static function ($iterable): IterableIterator {
Expand All @@ -46,7 +46,7 @@ public function on(iterable $collection): Closure
$items = array_merge([$collection], $iterables);

$walk = new Walk($getIteratorCallback);
$append = new Append($items);
$append = new Append(...$items);

$iterators = new ClosureIterator(
$walk->on(new ClosureIterator($append->on([])))
Expand Down

0 comments on commit 978323e

Please sign in to comment.