Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Collection Laravel Package

atournayre/collection

Type-safe PHP collections with list/map factories, plus immutable variants. Includes DecimalValue collections with consistent precision handling. Build domain-specific collections by extending TypedCollection to enforce item types and safe manipulation.

View on GitHub
Deep Wiki
Context7

Atournayre Collection

This library provides a way to manipulate collections.

Installation

Use Composer to install the package:

composer require atournayre/collection

Collections

Method Description
TypedCollection::createAsList() Create a list from an array
TypedCollection::createAsMap() Create a map from an array
TypedCollectionImmutable::createAsList() Create an immutable list from an array
TypedCollectionImmutable::createAsMap() Create an immutable map from an array
DecimalValueCollection::fromArray() Create a collection of DecimalValue from an array
DecimalValuePrecisionConsistentCollection::fromArray() Create a collection of DecimalValue with precision consistent from an array

Examples

Typed Collection

// Samples classes
class Person
{
    public function __construct(
        public string $name
    ) {}
}

class People extends TypedCollection
{
    protected static string $type = Person::class;
}
// Create collection
$collection = People::createAsList([
    new Person('John'),
]);
$collection[] = new Person('Jack'); // Add item

Typed Collection Immutable

// Samples classes
class Person
{
    public function __construct(
        public string $name
    ) {}
}

class People extends TypedCollectionImmutable
{
    protected static string $type = Person::class;
}
// Create collection
$collection = People::createAsList([
    new Person('John'),
]);
$collection[] = new Person('Jack'); // Throws a RuntimeException

Decimal Collection

$collection = DecimalValueCollection::fromArray([
    DecimalValue::create(4.235, 3),
    DecimalValue::fromInt(1),
    DecimalValue::fromString('2'),
    DecimalValue::fromFloat(3.01, 2),
], 2);
$collection[0]->toFloat(); // 4.24
$collection[1]->toFloat(); // 1.00
$collection[2]->toFloat(); // 2.00
$collection[3]->toFloat(); // 3.01

Contribute

Contributions to the package are always welcome!

License

All contents of this package are licensed under the MIT license.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi