Skip to content

Commit

Permalink
Revert "[8.x] Add reduce with keys to collections and lazy collections (
Browse files Browse the repository at this point in the history
#35839)"

This reverts commit 08dbb8b.
  • Loading branch information
taylorotwell committed Jan 13, 2021
1 parent 2cd4fd8 commit 4ff3039
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 50 deletions.
18 changes: 0 additions & 18 deletions src/Illuminate/Collections/Collection.php
Expand Up @@ -884,24 +884,6 @@ public function reduce(callable $callback, $initial = null)
return array_reduce($this->items, $callback, $initial);
}

/**
* Reduce an associative collection to a single value.
*
* @param callable $callback
* @param mixed $initial
* @return mixed
*/
public function reduceWithKeys(callable $callback, $initial = null)
{
$result = $initial;

foreach ($this->items as $key => $value) {
$result = $callback($result, $value, $key);
}

return $result;
}

/**
* Replace the collection items with the given items.
*
Expand Down
18 changes: 0 additions & 18 deletions src/Illuminate/Collections/LazyCollection.php
Expand Up @@ -845,24 +845,6 @@ public function reduce(callable $callback, $initial = null)
return $result;
}

/**
* Reduce an associative collection to a single value.
*
* @param callable $callback
* @param mixed $initial
* @return mixed
*/
public function reduceWithKeys(callable $callback, $initial = null)
{
$result = $initial;

foreach ($this as $key => $value) {
$result = $callback($result, $value, $key);
}

return $result;
}

/**
* Replace the collection items with the given items.
*
Expand Down
14 changes: 0 additions & 14 deletions tests/Support/SupportCollectionTest.php
Expand Up @@ -3592,20 +3592,6 @@ public function testReduce($collection)
}));
}

/**
* @dataProvider collectionClassProvider
*/
public function testReduceWithKeys($collection)
{
$data = new $collection([
'foo' => 'bar',
'baz' => 'qux',
]);
$this->assertEquals('foobarbazqux', $data->reduceWithKeys(function ($carry, $element, $key) {
return $carry .= $key.$element;
}));
}

/**
* @dataProvider collectionClassProvider
*/
Expand Down

0 comments on commit 4ff3039

Please sign in to comment.