Skip to content

Commit

Permalink
Move the run() method from Collection to Base.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Sep 1, 2019
1 parent 71f2702 commit 55a0e3d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,14 @@ use drupol\collection\Operation\All;
use drupol\collection\Operation\Run;
use drupol\collection\Contract\Operation;

$customCollectionClass = new class extends Base implements Allable, Runable {
$customCollectionClass = new class extends Base implements Allable {

/**
* {@inheritdoc}
*/
public function all(): array {
return $this->run(new All());
}

/**
* {@inheritdoc}
*/
public function run(Operation ...$operations)
{
return (new Run(...$operations))->on($this);
}
};

$customCollection = new $customCollectionClass(new ArrayObject(['A', 'B', 'C']));
Expand Down
10 changes: 10 additions & 0 deletions src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace drupol\collection;

use drupol\collection\Contract\Base as BaseInterface;
use drupol\collection\Contract\Operation;
use drupol\collection\Iterator\ClosureIterator;
use drupol\collection\Operation\Run;

/**
* Class Base.
Expand Down Expand Up @@ -55,6 +57,14 @@ public function getIterator(): ClosureIterator
return new ClosureIterator($this->source);
}

/**
* {@inheritdoc}
*/
public function run(Operation ...$operations)
{
return (new Run(...$operations))->on($this);
}

/**
* @param array $data
*
Expand Down
9 changes: 0 additions & 9 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use drupol\collection\Contract\Base as BaseInterface;
use drupol\collection\Contract\Collection as CollectionInterface;
use drupol\collection\Contract\Operation;
use drupol\collection\Operation\All;
use drupol\collection\Operation\Append;
use drupol\collection\Operation\Apply;
Expand Down Expand Up @@ -305,14 +304,6 @@ public function reduction(callable $callback, $initial = null): BaseInterface
return new Collection($this->run(new Reduction($callback, $initial)));
}

/**
* {@inheritdoc}
*/
public function run(Operation ...$operations)
{
return (new Run(...$operations))->on($this);
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
/**
* Interface Base.
*/
interface Base extends \IteratorAggregate
interface Base extends \IteratorAggregate, Runable
{
}
1 change: 0 additions & 1 deletion src/Contract/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface Collection extends
Rebaseable,
Reduceable,
Reductionable,
Runable,
Skipable,
Sliceable,
Sortable,
Expand Down

0 comments on commit 55a0e3d

Please sign in to comment.