PHPackages                             guennichi/collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. guennichi/collection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

guennichi/collection
====================

A lightweight PHP &gt;= 8.1 library to create immutable collections of objects

1.0.3(3y ago)050MITPHPPHP ^8.1

Since Aug 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/rguennichi/collection)[ Packagist](https://packagist.org/packages/guennichi/collection)[ RSS](/packages/guennichi-collection/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Collection
==========

[](#collection)

A lightweight PHP &gt;= 8.1 library to create **immutable/readonly** and strictly typed collection of objects.

Installation
------------

[](#installation)

```
composer require guennichi/collection
```

Usage
-----

[](#usage)

```
use Guennichi\Collection\Collection;

final class Person
{
    public function __construct(public readonly string $name) {}
}

/**
 * @extends Collection
 */
final class PersonCollection extends Collection
{
    public function __construct(Person ...$elements)
    {
        parent::__construct(...$elements);
    }
}

$persons = new PersonCollection(
    new Person('Person1'),
    new Person('Person2'),
    new Person('Person3'),
);

$persons->first()->name // Person1. Also supports autocomplete, thanks @template annotations.
$persons->contains(new Person('Person1')); // false
$persons->count(); // 3
count($persons); // 3
$persons->each(static function (Person $person, int $index) {
    // Do something
});
$persons->filter(static fn (Person $person) => $person->name === 'Person3'); // new PersonCollection instance with [Person('Person3')]

final class Employee
{
    public function __construct(public readonly string $name) {}
}

/**
 * @extends Collection
 */
final class EmployeeCollection extends Collection
{
    public function __construct(Employee ...$elements)
    {
        parent::__construct(...$elements);
    }
}

$employees = $persons->filter(static fn (Person $person) => in_array($person->name, ['Person1', 'Person3']))
                     ->mapTo(EmployeeCollection::class, static fn (Person $person) => new Employee($person->name));

foreach ($employees as $employee) {
    // $employee is instanceof Employee class
}

$employees->first(); // Employee('Person1'): instance of Employee class
$employees->every(static fn (Employee $employee) => !empty($employee->name)); // True
$employees->sortAscBy(static fn (Employee $employee) => $employee->name); // new collection instance with [Employee('Person1'), Employee('Person3')]
$employees->sortDescBy(static fn (Employee $employee) => $employee->name); // new collection instance with [Employee('Person3'), Employee('Person1')]

json_encode($employees) // [{"name":"Person1"}, {"name":"Person3"}]
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

4

Last Release

1335d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/287419?v=4)[Radhi](/maintainers/Radhi)[@radhi](https://github.com/radhi)

---

Top Contributors

[![rguennichi](https://avatars.githubusercontent.com/u/88873441?v=4)](https://github.com/rguennichi "rguennichi (10 commits)")

---

Tags

collectionimmutablereadonly

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/guennichi-collection/health.svg)

```
[![Health](https://phpackages.com/badges/guennichi-collection/health.svg)](https://phpackages.com/packages/guennichi-collection)
```

###  Alternatives

[phpcollection/phpcollection

General-Purpose Collection Library for PHP

1.0k64.0M34](/packages/phpcollection-phpcollection)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[lorisleiva/lody

Load files and classes as lazy collections in Laravel.

956.6M9](/packages/lorisleiva-lody)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
