Skip to content

Commit

Permalink
Move the creation of the new Collection in the Base class.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 10, 2019
1 parent b82b610 commit 70181f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getIterator(): ClosureIterator
*/
public function run(Operation ...$operations)
{
return (new Run(...$operations))->on($this);
return new static((new Run(...$operations))->on($this));
}

/**
Expand Down
66 changes: 33 additions & 33 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function all(): array
*/
public function append(...$items): BaseInterface
{
return new Collection($this->run(new Append($items)));
return $this->run(new Append($items));
}

/**
Expand All @@ -75,7 +75,7 @@ public function append(...$items): BaseInterface
*/
public function apply(callable ...$callables): BaseInterface
{
return new Collection($this->run(new Apply(...$callables)));
return $this->run(new Apply(...$callables));
}

/**
Expand All @@ -85,7 +85,7 @@ public function apply(callable ...$callables): BaseInterface
*/
public function chunk(int $size): BaseInterface
{
return new Collection($this->run(new Chunk($size)));
return $this->run(new Chunk($size));
}

/**
Expand All @@ -95,7 +95,7 @@ public function chunk(int $size): BaseInterface
*/
public function collapse(): BaseInterface
{
return new Collection($this->run(new Collapse()));
return $this->run(new Collapse());
}

/**
Expand All @@ -105,7 +105,7 @@ public function collapse(): BaseInterface
*/
public function combine($keys): BaseInterface
{
return new Collection($this->run(new Combine($keys)));
return $this->run(new Combine($keys));
}

/**
Expand All @@ -131,7 +131,7 @@ public function count(): int
*/
public function cycle(int $count = 0): BaseInterface
{
return new Collection($this->run(new Cycle($count)));
return $this->run(new Cycle($count));
}

/**
Expand All @@ -141,7 +141,7 @@ public function cycle(int $count = 0): BaseInterface
*/
public function distinct(): BaseInterface
{
return new Collection($this->run(new Distinct()));
return $this->run(new Distinct());
}

/**
Expand All @@ -161,7 +161,7 @@ public static function empty(): CollectionInterface
*/
public function explode(string ...$strings): BaseInterface
{
return new Collection($this->run(new Explode(...$strings)));
return $this->run(new Explode(...$strings));
}

/**
Expand All @@ -171,7 +171,7 @@ public function explode(string ...$strings): BaseInterface
*/
public function filter(callable ...$callbacks): BaseInterface
{
return new Collection($this->run(new Filter(...$callbacks)));
return $this->run(new Filter(...$callbacks));
}

/**
Expand All @@ -189,7 +189,7 @@ public function first(callable $callback = null, $default = null)
*/
public function flatten(int $depth = \PHP_INT_MAX): BaseInterface
{
return new Collection($this->run(new Flatten($depth)));
return $this->run(new Flatten($depth));
}

/**
Expand All @@ -199,7 +199,7 @@ public function flatten(int $depth = \PHP_INT_MAX): BaseInterface
*/
public function flip(): BaseInterface
{
return new Collection($this->run(new Flip()));
return $this->run(new Flip());
}

/**
Expand All @@ -209,7 +209,7 @@ public function flip(): BaseInterface
*/
public function forget(...$keys): BaseInterface
{
return new Collection($this->run(new Forget($keys)));
return $this->run(new Forget($keys));
}

/**
Expand All @@ -235,7 +235,7 @@ public function implode(string $glue = ''): string
*/
public function intersperse($element, int $every = 1, int $startAt = 0): BaseInterface
{
return new Collection($this->run(new Intersperse($element, $every, $startAt)));
return $this->run(new Intersperse($element, $every, $startAt));
}

/**
Expand Down Expand Up @@ -269,7 +269,7 @@ static function () use ($parameters, $callback) {
*/
public function keys(): BaseInterface
{
return new Collection($this->run(new Keys()));
return $this->run(new Keys());
}

/**
Expand All @@ -287,7 +287,7 @@ public function last()
*/
public function limit(int $limit): BaseInterface
{
return new Collection($this->run(new Limit($limit)));
return $this->run(new Limit($limit));
}

/**
Expand All @@ -297,7 +297,7 @@ public function limit(int $limit): BaseInterface
*/
public function map(callable ...$callbacks): BaseInterface
{
return new Collection($this->run(new Walk(...$callbacks), new Normalize()));
return $this->run(new Walk(...$callbacks), new Normalize());
}

/**
Expand All @@ -307,7 +307,7 @@ public function map(callable ...$callbacks): BaseInterface
*/
public function merge(...$sources): BaseInterface
{
return new Collection($this->run(new Merge($sources)));
return $this->run(new Merge($sources));
}

/**
Expand All @@ -317,7 +317,7 @@ public function merge(...$sources): BaseInterface
*/
public function normalize(): BaseInterface
{
return new Collection($this->run(new Normalize()));
return $this->run(new Normalize());
}

/**
Expand All @@ -327,7 +327,7 @@ public function normalize(): BaseInterface
*/
public function nth(int $step, int $offset = 0): BaseInterface
{
return new Collection($this->run(new Nth($step, $offset)));
return $this->run(new Nth($step, $offset));
}

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

/**
Expand All @@ -347,7 +347,7 @@ public function only(...$keys): BaseInterface
*/
public function pad(int $size, $value): BaseInterface
{
return new Collection($this->run(new Pad($size, $value)));
return $this->run(new Pad($size, $value));
}

/**
Expand All @@ -357,7 +357,7 @@ public function pad(int $size, $value): BaseInterface
*/
public function pluck($pluck, $default = null): BaseInterface
{
return new Collection($this->run(new Pluck($pluck, $default)));
return $this->run(new Pluck($pluck, $default));
}

/**
Expand All @@ -367,7 +367,7 @@ public function pluck($pluck, $default = null): BaseInterface
*/
public function prepend(...$items): BaseInterface
{
return new Collection($this->run(new Prepend($items)));
return $this->run(new Prepend($items));
}

/**
Expand All @@ -377,7 +377,7 @@ public function prepend(...$items): BaseInterface
*/
public static function range(int $start = 0, $end = \INF, $step = 1): CollectionInterface
{
return new Collection((new Collection())->run(new Range($start, $end, $step)));
return (new Collection())->run(new Range($start, $end, $step));
}

/**
Expand Down Expand Up @@ -405,7 +405,7 @@ public function reduce(callable $callback, $initial = null)
*/
public function reduction(callable $callback, $initial = null): BaseInterface
{
return new Collection($this->run(new Reduction($callback, $initial)));
return $this->run(new Reduction($callback, $initial));
}

/**
Expand All @@ -419,7 +419,7 @@ public function rsample($probability): BaseInterface
return (\mt_rand() / \mt_getrandmax()) < $probability;
};

return new Collection($this->run(new Filter($callback)));
return $this->run(new Filter($callback));
}

/**
Expand All @@ -429,7 +429,7 @@ public function rsample($probability): BaseInterface
*/
public function skip(int ...$counts): BaseInterface
{
return new Collection($this->run(new Skip(...$counts)));
return $this->run(new Skip(...$counts));
}

/**
Expand All @@ -439,7 +439,7 @@ public function skip(int ...$counts): BaseInterface
*/
public function slice(int $offset, int $length = null): BaseInterface
{
return new Collection($this->run(new Slice($offset, $length)));
return $this->run(new Slice($offset, $length));
}

/**
Expand All @@ -449,7 +449,7 @@ public function slice(int $offset, int $length = null): BaseInterface
*/
public function sort(callable $callback): BaseInterface
{
return new Collection($this->run(new Sort($callback)));
return $this->run(new Sort($callback));
}

/**
Expand All @@ -459,7 +459,7 @@ public function sort(callable $callback): BaseInterface
*/
public function split(callable ...$callbacks): BaseInterface
{
return new Collection($this->run(new Split(...$callbacks)));
return $this->run(new Split(...$callbacks));
}

/**
Expand All @@ -481,7 +481,7 @@ static function () use ($number) {
}
);

return null === $callback ? $instance : new Collection($instance->run(new Walk($callback)));
return null === $callback ? $instance : $instance->run(new Walk($callback));
}

/**
Expand All @@ -491,7 +491,7 @@ static function () use ($number) {
*/
public function walk(callable ...$callbacks): BaseInterface
{
return new Collection($this->run(new Walk(...$callbacks)));
return $this->run(new Walk(...$callbacks));
}

/**
Expand All @@ -511,6 +511,6 @@ public static function with($data = []): BaseInterface
*/
public function zip(...$items): BaseInterface
{
return new Collection($this->run(new Zip($items)));
return $this->run(new Zip($items));
}
}

0 comments on commit 70181f5

Please sign in to comment.