Skip to content

Commit

Permalink
refactor: Rename Group operation into GroupBy
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Yes
  • Loading branch information
drupol committed Oct 7, 2020
1 parent 46911c7 commit 248e5a4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions docs/pages/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -741,15 +741,15 @@ get

Interface: `Getable`_

group
~~~~~
groupBy
~~~~~~~

Group items, the key used to group items can be customized in a callback.
By default it's the key is the item's key.

Interface: `Groupable`_
Interface: `GroupByable`_

Signature: ``Collection::group(callable $callable = null);``
Signature: ``Collection::groupBy(?callable $callback = null);``

.. code-block:: php
Expand All @@ -768,7 +768,7 @@ Signature: ``Collection::group(callable $callable = null);``
};
$collection = Collection::fromIterable($callback)
->group();
->groupBy();
has
~~~
Expand Down Expand Up @@ -1965,7 +1965,7 @@ Signature: ``Collection::zip(iterable ...$iterables);``
.. _Forgetable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Forgetable.php
.. _Frequencyable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Frequencyable.php
.. _Getable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Getable.php
.. _Groupable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Groupable.php
.. _GroupByable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/GroupByable.php
.. _Hasable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Hasable.php
.. _Headable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Headable.php
.. _IfThenElseable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/IfThenElseable.php
Expand Down
8 changes: 4 additions & 4 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ public function it_can_get_the_last_item(): void
]);
}

public function it_can_group()
public function it_can_groupBy(): void
{
$callback = static function () {
yield 1 => 'a';
Expand All @@ -997,7 +997,7 @@ public function it_can_group()
};

$this::fromCallable($callback)
->group()
->groupBy()
->shouldIterateAs([
1 => [
'a',
Expand All @@ -1018,7 +1018,7 @@ public function it_can_group()
};

$this::fromIterable(range(0, 20))
->group($callback)
->groupBy($callback)
->shouldIterateAs([
'even' => [
0,
Expand Down Expand Up @@ -1049,7 +1049,7 @@ public function it_can_group()

$input = range(0, 20);
$this::fromIterable($input)
->group(static function () {return null; })
->groupBy(static function () {return null; })
->shouldIterateAs($input);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
use loophp\collection\Operation\Forget;
use loophp\collection\Operation\Frequency;
use loophp\collection\Operation\Get;
use loophp\collection\Operation\Group;
use loophp\collection\Operation\GroupBy;
use loophp\collection\Operation\Has;
use loophp\collection\Operation\Head;
use loophp\collection\Operation\IfThenElse;
Expand Down Expand Up @@ -508,9 +508,9 @@ public function getIterator(): ClosureIterator
return new ClosureIterator($this->source, ...$this->parameters);
}

public function group(?callable $callable = null): CollectionInterface
public function groupBy(?callable $callable = null): CollectionInterface
{
return $this->run(Group::of()($callable));
return $this->run(GroupBy::of()($callable));
}

public function has(callable $callback): bool
Expand Down
6 changes: 3 additions & 3 deletions src/Contract/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use loophp\collection\Contract\Operation\Forgetable;
use loophp\collection\Contract\Operation\Frequencyable;
use loophp\collection\Contract\Operation\Getable;
use loophp\collection\Contract\Operation\Groupable;
use loophp\collection\Contract\Operation\GroupByable;
use loophp\collection\Contract\Operation\Hasable;
use loophp\collection\Contract\Operation\Headable;
use loophp\collection\Contract\Operation\IfThenElseable;
Expand Down Expand Up @@ -143,7 +143,7 @@
* @template-extends Forgetable<TKey, T>
* @template-extends Frequencyable<TKey, T>
* @template-extends Getable<TKey, T>
* @template-extends Groupable<TKey, T>
* @template-extends GroupByable<TKey, T>
* @template-extends Hasable<TKey, T>
* @template-extends Headable<TKey, T>
* @template-extends IfThenElseable<TKey, T>
Expand Down Expand Up @@ -237,7 +237,7 @@ interface Collection extends
Forgetable,
Frequencyable,
Getable,
Groupable,
GroupByable,
Hasable,
Headable,
IfThenElseable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* @psalm-template TKey of array-key
* @psalm-template T
*/
interface Groupable
interface GroupByable
{
/**
* @psalm-return \loophp\collection\Contract\Collection<TKey, T>
*/
public function group(?callable $callback = null): Collection;
public function groupBy(?callable $callback = null): Collection;
}
2 changes: 1 addition & 1 deletion src/Operation/Group.php → src/Operation/GroupBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @psalm-template TKey of array-key
* @psalm-template T
*/
final class Group extends AbstractOperation
final class GroupBy extends AbstractOperation
{
/**
* @psalm-return Closure(null|callable(TKey, T):(TKey|null)): Closure(Iterator<TKey, T>): Generator<int, T|list<T>>
Expand Down

0 comments on commit 248e5a4

Please sign in to comment.