doctrine/collections
Doctrine Collections is a lightweight abstraction for working with arrays and object sets in PHP. Provides Collection interfaces and implementations like ArrayCollection, plus filtering, mapping, criteria-based matching, and iteration utilities used across Doctrine projects.
SplCollection, or custom implementations. Reduces technical debt and improves maintainability.filter(), map(), reduce(), and partition().ArrayCollection<int, User>) and improve developer experience.array_filter, array_map) with fluent, chainable methods.CollectionHelper) for common patterns (e.g., pagination, grouping).LazyCollection) for large datasets.ArrayHelper classes).Collection::groupByDate() for analytics).map, filter, reduce) without external libraries like underscore.php.SplObjectStorage, native arrays).immutables/immutable-collections or spatie/array-to-object.reactphp/collection or amp/collection.underscore.php or lodash.php for chaining syntax."Doctrine Collections is a battle-tested, MIT-licensed library that standardizes how we handle data structures across the codebase. By replacing ad-hoc arrays and custom implementations with a type-safe, optimized collection abstraction, we’ll:
Collection<User>).filter() and reduce() outperform manual loops."This package gives us:
users->filter(fn($u) => $u->isActive())).LazyCollection for pagination).Collection::groupBy('department')) without forking.
Migration is straightforward: swap array_filter($users) for $users->filter().
Trade-offs:Criteria for complex queries)."Key wins:
foreach hell: Use map(), reduce(), or partition() for cleaner code.contains(), first(), and last().LazyCollection.
Example:// Before
$activeUsers = array_filter($users, fn($u) => $u->isActive());
$names = array_map(fn($u) => $u->name, $activeUsers);
// After
$names = $users->filter(fn($u) => $u->isActive())->map(fn($u) => $u->name);
Start with ArrayCollection; migrate to custom collections later if needed."
How can I help you explore Laravel packages today?