innmind/immutable
Innmind/Immutable provides persistent, immutable collections for PHP, including sequences, sets, maps, and streams. It offers a functional API with lazy operations, structural sharing, and type-safe wrappers for predictable, side-effect-free data manipulation.
innmind/immutable supplies ready-made wrappers for PHP primitives (Str, NonEmptyString, Map, Set, Sequence, Vector, etc.). The decision it informs is whether your team hand-rolls a dozen DTO/VO classes per bounded context or adopts a small MIT-licensed dependency. For a team that has already written two or more internal "StringValue"/"Money"/"Id" base classes, this is a credible replacement for that bespoke layer.map/filter/flatMap over immutable sequences than as nested foreach with accumulator arrays. Useful when scoping features like "configurable report builder" or "bulk pricing recalculation."Consider it when:
map/filter) and would use these types naturally rather than fighting them.Look elsewhere when:
Collection, readonly properties (PHP 8.1+), and enums already cover 90% of the need with zero new dependency.spatie/laravel-data, brick/math, ramsey/uuid, Laravel's Collection, or doctrine/collections give you wider community support and familiar APIs for the same problems.Adoption criteria (gate before committing): a pilot in one bounded module; a documented boundary adapter to and from Eloquent models and JSON; a review of the dependency's release cadence and open issues; an internal fork/vendoring plan; and a team agreement that the style will be used in the target module only, not enforced globally.
To executives (30 seconds): "We're proposing a small MIT-licensed library for one specific module — [pricing / billing / ledger] — that makes our data values unchangeable once created. The business case is defect prevention, not features: it eliminates a class of bugs where a number or record gets silently altered mid-process and produces a wrong charge, wrong total, or wrong report. Those bugs are rare, hard to reproduce, and expensive to reconcile. Cost is near zero in licensing and roughly one sprint of team ramp-up, contained to one module. The honest risk is that the library is small and essentially one maintainer, so we'd pin the version and keep the option to vendor it. I'd like approval for a scoped pilot with a go/no-go at the end."
To engineering leadership / architects:
Str, NonEmptyString, Map, Sequence) so validation lives at construction rather than being re-checked in every method.How can I help you explore Laravel packages today?