PHPackages                             jarjak/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. jarjak/collection

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

jarjak/collection
=================

Immutable, type-aware PHP Collection.

0.4.2(4y ago)120.0k—8.7%[3 issues](https://github.com/JarJak/Collection/issues)MITPHPPHP &gt;=7.1

Since Nov 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/JarJak/Collection)[ Packagist](https://packagist.org/packages/jarjak/collection)[ Docs](https://github.com/JarJak/Collection)[ RSS](/packages/jarjak-collection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (9)Used By (0)

Immutable, type-aware PHP Collection
====================================

[](#immutable-type-aware-php-collection)

Collection pattern implementation with map, flatMap, reduce, sort, unique etc. methods. Serializable to JSON.

Requirements
------------

[](#requirements)

PHP &gt;= 7.1

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

[](#installation)

This package is available on composer via packagist.

`composer require jarjak/collection`

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

```
use JarJak\Collection\Collection;

$dateArray = [
    new DateTime(),
    new DateTimeImmutable(),
];

$dateCollection = new Collection(...$dateArray);
# or
$dateCollection = Collection::from($dateArray);

# then do what you know from other collection implementations
$plusYears = $dateCollection
    ->map(fn($date) => $date->modify('+1 year'))
    ->toArray();
```

### Adding type check feature

[](#adding-type-check-feature)

One of the coolest features of this implementation is that you can set up your own specific, type-aware collections (think about them like aggregates / repositories). Then you can encapsulate any custom operations that you need to perform on a group of same-type objects (instead for doing it in foreach loop somewhere in your controller / service).

```
use JarJak\Collection\Collection;

class DateCollection extends Collection
{
    // accept only date objects
    public function __construct(DateTimeInterface ...$items)
    {
        parent::__construct(...$items);
    }

    // you can personalize it by adding custom methods too!
    public function getMaxYear(): int
    {
        return $this->reduce(
            0,
            function (int $current, DateTimeInterface $date): int {
                $year = (int) $date->format('Y');
                return $current > $year ? $current : $year;
            }
        );
    }
}

# this is acceptable
$dateCollection = new DateCollection(
    new DateTime(),
    new DateTimeImmutable()
);
# this will result in an error
$dateCollection = new DateCollection(
    new DateTime(),
    new DateTimeImmutable(),
    date('now')
);

# then this will work
$plusYears = $dateCollection->map(fn($date) => $date->modify('+1 year'));
# but this won't
$dateStrings = $dateCollection->map(fn($date) => $date->format('Y-m-d'));
# unless you explicitly disable type check (which effectively sends you back to the base Collection class)
$dateStrings = $dateCollection
    ->disableTypeCheck()
    ->map(fn($date) => $date->format('Y-m-d'));
```

Inspired by
-----------

[](#inspired-by)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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 ~73 days

Recently: every ~86 days

Total

8

Last Release

1493d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b15155a25fa5e1512a22d31ce0c7ebb250d90e4b07804f3457f206e373d6069?d=identicon)[JarJak](/maintainers/JarJak)

---

Top Contributors

[![JarJak](https://avatars.githubusercontent.com/u/4981490?v=4)](https://github.com/JarJak "JarJak (1 commits)")

---

Tags

collectionimmutable

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/jarjak-collection/health.svg)](https://phpackages.com/packages/jarjak-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)[chdemko/sorted-collections

Sorted Collections for PHP &gt;= 8.2

222.5M3](/packages/chdemko-sorted-collections)

PHPackages © 2026

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