assegaiphp / collections
Typed collection, list, set, queue, and stack primitives for modern PHP applications.
Requires
- php: >=8.4
Requires (Dev)
- pestphp/pest: ^4.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-16 15:17:22 UTC
README
AssegaiPHP Collections
Typed collection, list, set, queue, and stack primitives for modern PHP applications.
assegaiphp/collections provides small in-memory collection types used across the AssegaiPHP ecosystem. Each concrete collection receives an item type and enforces it when values enter the collection.
The package includes:
Collectionfor general typed collectionsItemListfor indexed access, searching, insertion, and removalSetfor unique values and set operationsQueuefor first-in, first-out accessStackfor last-in, first-out access
Requirements
- PHP 8.4 or newer
Installation
composer require 'assegaiphp/collections:~0.11.0'
Usage
Create a collection by declaring the accepted PHP type:
use Assegai\Collections\Collection; $numbers = new Collection('integer', [1, 2, 3]); $numbers->add(4); $even = $numbers->filter(fn(int $number): bool => $number % 2 === 0); $doubled = $numbers->map(fn(int $number): int => $number * 2); $total = $numbers->reduce(fn(int $carry, int $number): int => $carry + $number, 0);
Passing a value that does not match the declared type raises a TypeError.
ItemList adds indexed access and search operations:
use Assegai\Collections\ItemList; $names = new ItemList('string', ['Ada', 'Grace', 'Margaret']); echo $names[0]; $index = $names->findIndex(fn(string $name): bool => $name === 'Grace');
Class names can be used as the declared type for object collections.
Contributing
For contribution and pull request conventions, see Commit and PR Guidelines.
License
AssegaiPHP Collections is MIT licensed.