PHPackages                             innmind/immutable - 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. innmind/immutable

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

innmind/immutable
=================

Immutable PHP primitive wrappers

6.2.0(1mo ago)74228.5k↓41%4[4 issues](https://github.com/Innmind/Immutable/issues)20MITPHPPHP ~8.4CI passing

Since Jan 9Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/Innmind/Immutable)[ Packagist](https://packagist.org/packages/innmind/immutable)[ Docs](http://github.com/Innmind/Immutable)[ RSS](/packages/innmind-immutable/feed)WikiDiscussions develop Synced yesterday

READMEChangelog (10)Dependencies (6)Versions (125)Used By (20)

Immutable
=========

[](#immutable)

[![Build Status](https://github.com/Innmind/Immutable/workflows/CI/badge.svg?branch=master)](https://github.com/Innmind/Immutable/actions?query=workflow%3ACI)[![codecov](https://camo.githubusercontent.com/cad52d858c055b9b85c7a4cdafc840d6c7270f93e7abe275111a2532ca8241cc/68747470733a2f2f636f6465636f762e696f2f67682f496e6e6d696e642f496d6d757461626c652f6272616e63682f646576656c6f702f67726170682f62616467652e737667)](https://codecov.io/gh/Innmind/Immutable)[![Type Coverage](https://camo.githubusercontent.com/cebd4477674a0aa5dc6bb71a708d1140372cd6b0bc2f7e0aedc51a4a55cd3bc1/68747470733a2f2f73686570686572642e6465762f6769746875622f496e6e6d696e642f496d6d757461626c652f636f7665726167652e737667)](https://shepherd.dev/github/Innmind/Immutable)

A set of classes to wrap PHP primitives to build immutable data.

[Documentation](https://innmind.github.io/Immutable/)

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

[](#installation)

```
composer require innmind/immutable
```

Usage
-----

[](#usage)

Here are some examples of what you can do:

### Sequence

[](#sequence)

To be used to wrap an ordered list of elements (elements can be of mixed types).

```
use Innmind\Immutable\Sequence;

$seq = Sequence::of(24, 42, 'Hitchhiker', 'Magrathea');
$seq->get(2); // Maybe::just(Hitchhiker)
$another = $seq->drop(2);
$another->toList(); // [Hitchhiker, Magrathea]
$seq->toList(); // [24, 42, Hitchhiker, Magrathea]

//----
// this example demonstrates the lazyness capability of the sequence
// precisely here it's able to read a file line by line and echo the lines
// that are less than 42 characters long (without requiring to load the whole
// file in memory)
$someFile = fopen('some/file.txt', 'r');
$lines = Sequence::lazy(fn() => yield fgets($someFile))
    ->filter(fn($line) => strlen($line) < 42);
// at this point no reading to the file has been done because all methods
// returning a new instance of a sequence will pipeline the operations to do,
// allowing to chain complex logic while accessing the original data once and
// without the need to keep the discarded data along the pipeline in memory
$lines->foreach(fn($line) => echo($line));
```

For a complete list of methods check [`Sequence`](src/Sequence.php).

### Set

[](#set)

To be used as a collection of unordered elements (elements must be of the same type).

```
use Innmind\Immutable\Set;

$set = Set::of(24, 42);
$set->equals(Set::of(24, 42)); // true
$set->add(42.0); // psalm will raise an error
```

For a complete list of methods check [`Set`](src/Set.php).

### Map

[](#map)

To be used as a collection of key/value pairs (both keys and values must be of the same type).

```
use Innmind\Immutable\Map;

$map = Map::of(
    [new \stdClass, 42]
    [$key = new \stdClass, 24]
);
$map->size(); // 2, because it's 2 different instances
$map->values()->toList(); // [42, 24]
$map = $map->put($key, 66);
$map->size(); // 2
$map->values()->toList(); // [42, 66]
```

For a complete list of methods check [`Map`](src/Map.php).

### Strings

[](#strings)

```
use Innmind\Immutable\Str;

$var = Str::of('the hitchhiker\'s guide to the galaxy');
echo $var
    ->replace('galaxy', '42') // the hitchhiker's guide to the 42
    ->drop(18) // guide to the 42
    ->toUpper()
    ->toString(); // outputs: GUIDE TO THE 42
echo $var->toString(); // outputs: the hitchhiker\'s guide to the galaxy
```

Regular expressions
-------------------

[](#regular-expressions)

```
use Innmind\Immutable\{
    RegExp,
    Str,
};

$regexp = RegExp::of('/(?\d+)/');
$regexp->matches(Str::of('foo123bar')); // true
$regexp->matches(Str::of('foobar')); // false
$regexp->capture(Str::of('foo123bar')); // Map with index `i` set to Str::of('123')
```

### [BlackBox](https://github.com/innmind/blackbox/)

[](#blackbox)

This library provides 2 `Set`s that can be used with [`innmind/black-box`](https://packagist.org/packages/innmind/black-box).

You can use them as follow:

```
use Innmind\BlackBox\{
    PHPUnit\BlackBox,
    Set,
};
use Fixtures\Innmind\Immutable;

class SomeTest extends \PHPUnit\Framework\TestCase
{
    use BlackBox;

    public function testSomeProperty()
    {
        $this
            ->forAll(
                Immutable\Set::of(
                    Set\RealNumbers::any(),
                ),
                Immutable\Sequence::of(
                    Set\Uuid::any(),
                ),
            )
            ->then(function($set, $sequence) {
                // $set is an instance of \Innmind\Immutable\Set
                // $sequence is an instance of \Innmind\Immutable\Sequence

                // write your test here
            });
    }
}
```

###  Health Score

70

—

ExcellentBetter than 100% of packages

Maintenance89

Actively maintained with recent releases

Popularity46

Moderate usage in the ecosystem

Community32

Small or concentrated contributor base

Maturity98

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 99% 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 ~31 days

Recently: every ~63 days

Total

122

Last Release

50d ago

Major Versions

1.12.0 → 2.0.02017-02-12

2.17.0 → 3.0.02019-12-08

3.12.0 → 4.0.02021-09-05

4.15.0 → 5.0.02023-09-16

5.20.0 → 6.0.02026-01-11

PHP version history (8 changes)0.5.0PHP &gt;=5.6

1.0.0PHP ~7.0

2.9.0PHP ~7.1

3.0.0PHP ~7.4

3.9.0PHP ~7.4|~8.0

4.0.0PHP ~8.0

4.15.0PHP ~8.2

6.0.0PHP ~8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/851425?v=4)[Baptiste Langlade](/maintainers/Baptouuuu)[@Baptouuuu](https://github.com/Baptouuuu)

---

Top Contributors

[![Baptouuuu](https://avatars.githubusercontent.com/u/851425?v=4)](https://github.com/Baptouuuu "Baptouuuu (969 commits)")[![jdecool](https://avatars.githubusercontent.com/u/433926?v=4)](https://github.com/jdecool "jdecool (5 commits)")[![ngdo-pro](https://avatars.githubusercontent.com/u/22030946?v=4)](https://github.com/ngdo-pro "ngdo-pro (2 commits)")[![drupol](https://avatars.githubusercontent.com/u/252042?v=4)](https://github.com/drupol "drupol (1 commits)")[![nclsHart](https://avatars.githubusercontent.com/u/833625?v=4)](https://github.com/nclsHart "nclsHart (1 commits)")[![quentint](https://avatars.githubusercontent.com/u/349104?v=4)](https://github.com/quentint "quentint (1 commits)")

---

Tags

wrapperimmutable

### Embed Badge

![Health badge](/badges/innmind-immutable/health.svg)

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

###  Alternatives

[simplesoftwareio/simple-qrcode

Simple QrCode is a QR code generator made for Laravel.

2.9k30.5M113](/packages/simplesoftwareio-simple-qrcode)[artisaninweb/laravel-soap

A SoapClient wrapper integration for Laravel

6404.7M13](/packages/artisaninweb-laravel-soap)[aeon-php/calendar

PHP type safe, immutable calendar library

20810.4M16](/packages/aeon-php-calendar)[mhor/php-mediainfo

PHP wrapper around the mediainfo command

120597.4k8](/packages/mhor-php-mediainfo)[bocharsky-bw/arrayzy

A native PHP arrays easy manipulation library in OOP way.

38427.7k](/packages/bocharsky-bw-arrayzy)[trafficcophp/bytebuffer

Node.js inspired byte stream buffer for PHP.

33478.1k19](/packages/trafficcophp-bytebuffer)

PHPackages © 2026

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