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

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

pitchart/collection
===================

A simple immutable collection library with functional capabilities

v1.3.0(9y ago)1271MITPHPPHP &gt;=5.5

Since Jan 9Pushed 9y ago1 watchersCompare

[ Source](https://github.com/pitchart/collection)[ Packagist](https://packagist.org/packages/pitchart/collection)[ RSS](/packages/pitchart-collection/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (8)Used By (0)

Collection
==========

[](#collection)

A simple immutable collection library with a fluent API.

[![License: MIT](https://camo.githubusercontent.com/1a2e0606685ce00663bf829868f794fd3fc9c86f8d80cae324734129e0723a58/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d627269676874677265656e2e737667)](https://opensource.org/licenses/MIT)[![Latest Stable Version](https://camo.githubusercontent.com/88da4612d07d86180f3e7eda78f4356306f19036c138a8991077fa9e6e65f9cf/68747470733a2f2f706f7365722e707567782e6f72672f70697463686172742f636f6c6c656374696f6e2f762f737461626c65)](https://packagist.org/packages/pitchart/collection)[![Build Status](https://camo.githubusercontent.com/0b2112df8c7c7691a966917ac94f8b19f1590e877a98c2f67c99f9ff1a92df93/68747470733a2f2f7472617669732d63692e6f72672f70697463686172742f636f6c6c656374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pitchart/collection)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f4f0edf0ad7aa3871113bafdbf82fa5aaba54bf3df4c932b2f7a0140e4052957/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70697463686172742f636f6c6c656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/pitchart/collection/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/cd4baab49f8cfd0d73885e094854e3012fab188dc314b57f31c2d65560880c95/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70697463686172742f636f6c6c656374696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/pitchart/collection/?branch=master)

Install
-------

[](#install)

```
composer require pitchart/collection
```

Usage
-----

[](#usage)

Use the `Collection` class to manipulate array datas :

```
use Pitchart\Collection\Collection;

$numbers = Collection::from([1, 2, 3, 4]);
$plusOneNumbers = $numbers->map(function ($item) {
     return $item + 1;
});
$evenNumbers = $plusOneNumbers->filter(function ($item) {
    return $item % 2 == 0;
});
$total = $evenNumbers->reduce(function ($accumulator, $item) {
    return $accumulator + $item;
}, 0);
```

### Collection pipelines

[](#collection-pipelines)

> Collection pipelines are a programming pattern where you organize some computation as a sequence of operations which compose by taking a collection as output of one operation and feeding it into the next. **[Martin Fowler](https://martinfowler.com/articles/collection-pipeline/)**

This library is designed for collection pipelines usage as it offers a large catalogue of common collection operations.

The previous example can be rewriten like :

```
$total = Collection::from([1, 2, 3, 4])
    ->map(function ($item) {
        return $item + 1;
    })
    ->filter(function ($item) {
        return $item % 2 == 0;
    })
    ->reduce(function ($accumulator, $item) {
        return $accumulator + $item;
    }, 0);
```

### Speed up operations thanks to generators

[](#speed-up-operations-thanks-to-generators)

If you need to manipulate heavy number of datas or reduce the memory impact of heavy intermediate transformation, you can use the `GeneratorCollection` class :

```
use Pitchart\Collection\GeneratorCollection;

$collection = Collection::from($heavyFolderList)
	->map(function ($folder) {
		return loadContentFromFilesInFolder($folder);
	})
	->filter(function ($content) {
		return lotsOfRegexpContentFiltering($content);
	})
	->reduce(function ($accumulator, $content) {
		return $accumulator.retrievePartsToCollect($content);
	}, '');
```

As a generator can be traversed only once, the result can be persisted in a classic Collection to be used as data source for multiples transformations :

```
/** @var Collection $reusableCollection */
$reusableCollection = $generatorCollection->persist();
```

### Functional helpers

[](#functional-helpers)

This package provides functional helpers to use collection pipelines focused on operations :

```
use function Pitchart\Collection\Helpers\map;

map([1, 2, 3, 4], function ($item) {
    return $item + 1;
})
->filter(function ($item) {
    return $item % 2 == 0;
});
```

You can also use them to perform operations on any iterable datas, IE arrays or traversable objects, with a consistent API.

Test
----

[](#test)

```
make test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Total

6

Last Release

3365d ago

PHP version history (3 changes)v1.0.1PHP &gt;=5.4.0

v1.2.0PHP &gt;=5.4

v1.3.0PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d434eb5aaedc60d5fb046facaf6445f1f1e52260d6776e3af30f1a7541d6385?d=identicon)[pitchart](/maintainers/pitchart)

---

Top Contributors

[![pitchart](https://avatars.githubusercontent.com/u/2943883?v=4)](https://github.com/pitchart "pitchart (76 commits)")

---

Tags

collectionfunctionalimmutable

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

344146.0k](/packages/qaribou-immutablephp)[chippyash/monad

Functional programming Monad support

2828.1k8](/packages/chippyash-monad)

PHPackages © 2026

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