Skip to content

Commit

Permalink
refactor: Remove Reduce operation.
Browse files Browse the repository at this point in the history
Use FoldLeft operation instead.

BREAKING CHANGE: yes
  • Loading branch information
drupol committed Oct 7, 2020
1 parent e3b3261 commit 42934a9
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 99 deletions.
6 changes: 0 additions & 6 deletions docs/pages/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,6 @@ Signature: ``Collection::random(int $size = 1);``
$collection = Collection::fromIterable(['4', '5', '6'])
->random(); // ['6']
reduce
~~~~~~

Interface: `Reduceable`_

reduction
~~~~~~~~~

Expand Down Expand Up @@ -2010,7 +2005,6 @@ Signature: ``Collection::zip(iterable ...$iterables);``
.. _Prependable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Prependable.php
.. _Productable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Productable.php
.. _Randomable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Randomable.php
.. _Reduceable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Reduceable.php
.. _Reductionable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Reductionable.php
.. _Reverseable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Reverseable.php
.. _Scaleable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Scaleable.php
Expand Down
12 changes: 0 additions & 12 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -1714,18 +1714,6 @@ public function it_can_random(): void
->shouldNotIterateAs($generator($input));
}

public function it_can_reduce(): void
{
$this::fromIterable(range(1, 100))
->reduce(
static function ($carry, $item) {
return $carry + $item;
},
0
)
->shouldReturn(5050);
}

public function it_can_reduction(): void
{
$this::fromIterable(range(1, 5))
Expand Down
6 changes: 0 additions & 6 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
use loophp\collection\Operation\Product;
use loophp\collection\Operation\Random;
use loophp\collection\Operation\Range;
use loophp\collection\Operation\Reduce;
use loophp\collection\Operation\Reduction;
use loophp\collection\Operation\Reverse;
use loophp\collection\Operation\RSample;
Expand Down Expand Up @@ -688,11 +687,6 @@ public static function range(float $start = 0.0, float $end = INF, float $step =
return (new self())->pipe(Range::of()($start)($end)($step));
}

public function reduce(callable $callback, $initial = null)
{
return $this->pipe(Reduce::of()($callback)($initial))->getIterator()->current();
}

public function reduction(callable $callback, $initial = null): CollectionInterface
{
return $this->pipe(Reduction::of()($callback)($initial));
Expand Down
3 changes: 0 additions & 3 deletions src/Contract/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
use loophp\collection\Contract\Operation\Productable;
use loophp\collection\Contract\Operation\Randomable;
use loophp\collection\Contract\Operation\Rangeable;
use loophp\collection\Contract\Operation\Reduceable;
use loophp\collection\Contract\Operation\Reductionable;
use loophp\collection\Contract\Operation\Reverseable;
use loophp\collection\Contract\Operation\RSampleable;
Expand Down Expand Up @@ -173,7 +172,6 @@
* @template-extends Prependable<TKey, T>
* @template-extends Productable<TKey, T>
* @template-extends Randomable<TKey, T>
* @template-extends Reduceable<TKey, T>
* @template-extends Reductionable<TKey, T>
* @template-extends Reverseable<TKey, T>
* @template-extends RSampleable<TKey, T>
Expand Down Expand Up @@ -274,7 +272,6 @@ interface Collection extends
Productable,
Randomable,
Rangeable,
Reduceable,
Reductionable,
Reverseable,
RSampleable,
Expand Down
24 changes: 0 additions & 24 deletions src/Contract/Operation/Reduceable.php

This file was deleted.

48 changes: 0 additions & 48 deletions src/Operation/Reduce.php

This file was deleted.

0 comments on commit 42934a9

Please sign in to comment.