Download the PHP package purrphp/pure-collection without Composer
On this page you can find all versions of the php package purrphp/pure-collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download purrphp/pure-collection
More information about purrphp/pure-collection
Files in purrphp/pure-collection
Package pure-collection
Short Description Immutable type-safe collections for PHP
License MIT
Homepage https://github.com/PurrPHP/pure-collection
Informations about the package pure-collection
PurrPHP/collection
Type-safe collections for PHP 8. Type safety based on native PHP features, not static analyzers. Inspired by Kotlin collections.
Documentation
- Common Methods — methods available on every collection
- Int Collections — integer-typed classes and their specific API
- String Collections — string-typed classes and their specific API
- Custom Collections — step-by-step guide for implementing your own typed collection
- Architecture Decisions — key design decisions and their rationale
Problem scope
PHP has no native typed collections — only plain arrays. This makes it easy to accidentally mix types or corrupt key structure:
This library solves these problems by providing type-safe, semantically clear collections that reduce boilerplate and prevent mistakes at runtime.
Code structure
Inspired by Kotlin collections, the library provides three collection types:
- List — ordered sequence with integer keys, duplicates allowed
- Set — ordered sequence of unique values
- Map — associative array (key → value)
Collections are immutable and return new object after each manipulation.
Hierarchy:
Available Classes
| Class | Description |
|---|---|
IntList |
Ordered list of integers |
IntSet |
Ordered list of unique integers |
IntNotEmptyList |
Same as IntList, throws on empty construction |
IntNotEmptySet |
Same as IntSet, throws on empty construction |
IntMap |
Associative (key → int) map |
StringList |
Ordered list of strings |
StringSet |
Ordered list of unique strings |
StringNotEmptySet |
Same as StringSet, throws on empty construction |
StringMap |
Associative (key → string) map |
Installation
Usage
Lists
Sets (unique values)
Maps
Common Operations
All collections implement CollectionInterface. See the full reference:
- Common Methods — searching, filtering, transforming, grouping, sizing, iteration
- Int Collections — aggregation, sorting, set operations variants
- String Collections — alphabetical sorting, set operations variants
Extending
To create a custom typed collection, extend AbstractList, AbstractSet, or AbstractMap. See detailed guide for custom implementation.
Development
With Docker / Make
License
MIT — see LICENSE.