raxos / collection
Collection primitives.
Requires
- php: >=8.5
- jetbrains/phpstorm-attributes: ^1.2
- raxos/contract: *
- raxos/error: *
- raxos/foundation: *
Requires (Dev)
- pestphp/pest: ^5.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Raxos Collection
Ordered lists, keyed maps and pagination objects with iterable, array-access and JSON support.
Documentation | Packagist | Raxos
- Mutable and read-only lists and maps.
- Validated string, integer and number lists.
- Filtering, projections, grouping, sorting, slicing and reductions.
- Paginated results with item and page metadata.
Installation
Requires PHP 8.5 or later. Composer checks the remaining package and extension dependencies declared in composer.json.
composer require "raxos/collection:^3.2"
Usage
<?php declare(strict_types=1); use Raxos\Collection\ArrayList; require __DIR__ . '/vendor/autoload.php'; $products = ArrayList::of([ ['name' => 'Keyboard', 'stock' => 5], ['name' => 'Mouse', 'stock' => 0], ]); $names = $products ->filter(static fn(array $product): bool => $product['stock'] > 0) ->map(static fn(array $product): string => $product['name']); echo json_encode($names);
Transformations leave the original collection intact. In 3.2, projections such as map(), column() and keys() return generic list interfaces rather than the original typed list. Read-only inputs keep read-only results.
Documentation
Testing
Run this library's Pest suite from the Raxos workspace:
git clone --recurse-submodules https://github.com/basmilius/raxos.git
cd raxos
composer install
vendor/bin/pest --testsuite=collection
See Testing Raxos for PHP extensions, integration services and coverage commands. The library's Tests workflow also runs in GitHub Actions.
License
MIT. Copyright (c) 2017 - present Bas Milius.