beauty-framework / collection
Beauty Collection
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/beauty-framework/collection
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^12.2
This package is not auto-updated.
Last update: 2025-10-10 14:20:35 UTC
README
A powerful collection abstraction for the Beauty Framework.
Supports both eager and lazy data pipelines, multiple storage strategies, method chaining (map, filter, sortBy, paginate, etc.), strict interfaces, and full compatibility.
Features
Collection (eager)
- Fluent methods:
map,filter,where,sortBy,paginate,each,first,last,values
- Implements:
ArrayAccess,Countable,IteratorAggregate,JsonSerializable
- Smart
last()optimization (iterator or buffered strategy) - Storage strategies:
ArrayStorage(default)DsMapStorage(ifext-dsis available)
LazyCollection
- Based on
Generator - Fluent methods:
map,filter,chunk,flatMap,reduce,take,first,toArray
- Memory efficient for large or infinite datasets
Interfaces
CollectionInterfaceSupportsOperationsSupportsAccessorsLazyCollectionInterface
Installation
composer require beauty-framework/collection
Usage
Eager Collection
$collection = new Collection([ ['name' => 'Kirill'], ['name' => 'Hui'], ['name' => 'Zver'], ]); $filtered = $collection ->where('name', 'Kirill') ->map(fn($x) => strtoupper($x['name'])) ->toArray();
Lazy Collection
$collection = new LazyCollection(fn() => yield from range(1, 1_000_000)); $result = $collection ->filter(fn($x) => $x % 2 === 0) ->take(5) ->flatMap(fn($x) => [$x, $x * 10]) ->toArray();
Tests
vendor/bin/phpunit
Compatibility
- ArrayAccess
- Countable
- IteratorAggregate
- JsonSerializable
License
MIT