Skip to content

Commit

Permalink
Update documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jul 6, 2021
1 parent 0a68a46 commit 872ecc6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/pages/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,10 @@ Filter collection items based on one or more callbacks.
If you're looking for a logical ``AND``, you have to make multiple calls to the
same operation.

.. tip:: It is only when the callback returns ``true`` that the value is kept.

.. tip:: If you're looking for keeping value in the iterator when the return is ``false``, see the ``reject`` operation.

Interface: `Filterable`_

Signature: ``Collection::filter(callable ...$callbacks);``
Expand Down Expand Up @@ -1663,6 +1667,26 @@ Signature: ``Collection::reduction(callable $callback, $initial = null);``
$collection = Collection::fromIterable(range(1, 5))
->reduction($callback); // [1, 3, 6, 10, 15]
reject
~~~~~~

Filter collection items based on one or more callbacks.

.. warning:: The `callbacks` parameter is variadic and will be evaluated as a logical ``OR``.
If you're looking for a logical ``AND``, you have to make multiple calls to the
same operation.

.. tip:: It is only when the callback returns ``false`` that the value is kept.

.. tip:: If you're looking for keeping value in the iterator when the return is ``true``, see the ``filter`` operation.

Interface: `Rejectable`_

Signature: ``Collection::reject(callable ...$callbacks);``

.. literalinclude:: code/operations/reject.php
:language: php

reverse
~~~~~~~

Expand Down Expand Up @@ -2385,6 +2409,7 @@ Signature: ``Collection::zip(iterable ...$iterables);``
.. _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
.. _Reductionable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Reductionable.php
.. _Rejectable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Rejectable.php
.. _Reverseable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Reverseable.php
.. _RSampleable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/RSampleable.php
.. _Scaleable: https://github.com/loophp/collection/blob/master/src/Contract/Operation/Scaleable.php
Expand Down
24 changes: 24 additions & 0 deletions docs/pages/code/operations/reject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App;

use loophp\collection\Collection;

include __DIR__ . '/../../../../vendor/autoload.php';

$divisibleBy2 = static fn ($value): bool => 0 === $value % 2;
$divisibleBy3 = static fn ($value): bool => 0 === $value % 3;
$divisibleBy4 = static fn ($value): bool => 0 === $value % 4;

$collection = Collection::fromIterable(range(1, 10))
->reject($divisibleBy2); // [1, 3, 5, 7, 9]

$collection = Collection::fromIterable(range(1, 10))
->reject($divisibleBy2, $divisibleBy3, $divisibleBy4); // [1, 5, 7]

0 comments on commit 872ecc6

Please sign in to comment.