This is an abstract base class that you can use for your collections. It extends ArrayIterator
and implements the Collection
interface (and already uses the CollectionTrait
) so you just need to extend it to have a proper collection class.
<?php
declare(strict_types=1);
use Kununu\Collection\AbstractCollection;
final class MyCollection extends AbstractCollection
{
}
$collection = MyCollection::fromIterable($myData);
Using the same concept as AbstractCollection
this class extends ArrayIterator
and implements the FilterableCollection
(and already uses the FilterableCollectionTrait
).
<?php
declare(strict_types=1);
use Kununu\Collection\AbstractFilterableCollection;
final class MyCollection extends AbstractFilterableCollection
{
}
$collection = MyCollection::fromIterable($myData);
$filtered = $collection->filter($filter);
$groups = $collection->groupBy(true, $group1Filter, $group2Filter);