Search by

assegaiphp / collections

amasiye

Typed collection, list, set, queue, and stack primitives for modern PHP applications.

Package info

github.com/assegaiphp/collections

pkg:composer/assegaiphp/collections

Statistics

Installs: 4 525

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

0.11.0 2026-11-16 10:47 UTC

This package is auto-updated.

Last update: 2026-11-16 15:17:22 UTC


README

AssegaiPHP Logo

Latest release Tests PHP 8.4+ License Status active

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:

  • Collection for general typed collections
  • ItemList for indexed access, searching, insertion, and removal
  • Set for unique values and set operations
  • Queue for first-in, first-out access
  • Stack for 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.