Download the PHP package oceanmoon/collections without Composer
On this page you can find all versions of the php package oceanmoon/collections. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oceanmoon/collections
More information about oceanmoon/collections
Files in oceanmoon/collections
Package collections
Short Description Type-safe PHP collections: Sequence (ordered list), Dictionary (any-type keys), Set (unique values), with runtime type validation.
License MIT
Homepage https://github.com/mossy2100/PHP-Collections
Informations about the package collections
OceanMoon PHP Collections
Type-safe collection classes for PHP 8.4+.
Documentation
Description
A type-safe collection library featuring runtime type validation, immutable operations, and unrestricted key types.
Core Classes:
- Sequence - Ordered lists with integer indexing
- Dictionary - Key-value pairs accepting any type as keys
- Set - Unique value collections with set operations
Development and Quality Assurance
Claude Chat and Claude Code were used in the development of this package. The core classes were designed, coded, and commented primarily by the author, with Claude providing substantial assistance with code review, suggesting improvements, debugging, and generating tests and documentation. All code was thoroughly reviewed by the author, and validated using industry-standard tools including PHP_Codesniffer, PHPStan (to level 9), and PHPUnit to ensure full compliance with PSR-12 coding standards and comprehensive unit testing with 100% code coverage. This collaborative approach has produced a well-designed, production-ready package with thorough test coverage and documentation.
Why OceanMoon Collections?
PHP's native arrays are powerful but have limitations:
- Keys restricted to strings and integers - Can't use booleans, floats, arrays, or objects as keys.
- No type safety - Arrays accept any mix of types without validation.
- Type coercion issues - Keys like
1,'1',true, and1.0all become the same key. - Limited operations - Built-in array functions lack chaining, immutability, and advanced transformations. Errors and exceptions are inconsistent.
OceanMoon Collections solves these problems with:
✅ Any type as keys - Use objects, arrays, booleans, floats, null as Dictionary keys.
✅ Runtime type validation - Optional type constraints with compile-time-like checking.
✅ Rich API - Fluent interfaces, method chaining, functional programming support.
✅ Immutable operations - Transformations return new collections without modifying originals.
✅ Type inference - Automatically detect types from your data.
✅ Mathematical correctness - Proper type safety for operations like sum() and product().
Alternatives
Before using this package, you may want to check out these PHP extensions:
These are official PHP extensions that provide efficient data structure implementations and will probably be well-supported going forward. However, if you need runtime type safety and generics-like behavior, or simply prefer a more functional style of programming, OceanMoon Collections provides features that these extensions lack, including type constraints, type inference, and type-safe operations.
Features
Type Safety
Unrestricted Keys
Functional Programming
Set Operations
Installation
Requirements
- PHP ^8.4
- oceanmoon/core
Quick Start
Sequence - Type-safe lists
Dictionary - Key-value pairs with any type
Set - Unique values
Classes
Core Collections
- Collection - Abstract base class providing shared functionality for all collection types
- Sequence - Ordered lists with integer indexing, similar to
List<T>in C# or Java - Dictionary - Key-value pairs accepting any PHP type for both keys and values
- Set - Unique value collections with mathematical set operations
Supporting Classes
- TypeSet - Runtime type validation and constraint management
- Pair - Immutable key-value pair container
Testing
The library includes comprehensive test coverage:
Test Coverage:
- 500+ tests across all classes
- 100% code coverage
- Edge cases, error conditions, and type safety
License
MIT License - see LICENSE for details
Support
- Issues: https://github.com/mossy2100/PHP-Collections/issues
- Documentation: See docs/ directory for detailed class documentation
- Examples: See test files for comprehensive usage examples
For questions or suggestions, please open an issue.
Changelog
See CHANGELOG.md for version history and changes.