Collection
The Collection package provides the list and map primitives used across the rest of Raxos. It ships an ordered, chainable ArrayList with a full set of functional operations, a set of typed list variants that validate their items, string keyed Map dictionaries, and a small Paginated value object for API responses. Every type is iterable, countable and JSON serializable, so it drops straight into HTTP responses and ORM relations.
Highlights
ArrayListMutable, chainable list with map, filter, reduce, chunk, groupBy and more.ReadonlyArrayListImmutable list that throws when you try to write through array access.StringArrayListTyped list that validates every item and adds string helpers.MapString keyed dictionary with get, set, has, unset and merge.CacheMapMap that memoizes the result of a callable per key.PaginatedImmutable value object wrapping a page of results with metadata.Explore by category
- Array lists:
ArrayListandReadonlyArrayList, construction, array access, iteration and the full set of chainable operations. - Typed lists:
StringArrayList,IntArrayListandNumberArrayListand how item validation works. - Maps:
Map,CacheMapandReadonlyMapstring keyed dictionaries. - Pagination: the
Paginatedvalue object and its JSON shape.
Quick example
php
<?php
declare(strict_types=1);
use Raxos\Collection\ArrayList;
$numbers = ArrayList::of([1, 2, 3, 4, 5]);
$result = $numbers
->filter(static fn(int $number): bool => $number % 2 === 1)
->map(static fn(int $number): int => $number * 10);
$result->toArray(); // [10, 30, 50]Installation
Install the package with Composer and check the requirements on the installation page.
shell
composer require raxos/collection