ghostwriter/collection

Provides a Collection implementation for PHP

2.0.0 2024-02-22 20:29 UTC

This package is auto-updated.

Last update: 2024-12-01 00:14:19 UTC


README

Compliance Supported PHP Version Mutation Coverage Code Coverage Type Coverage Latest Version on Packagist Downloads

Provides a Collection implementation for PHP.

Installation

You can install the package via composer:

composer require ghostwriter/collection

Star ⭐️ this repo if you find it useful

You can also star (🌟) this repo to find it easier later.

Usage

/** @var \Ghostwriter\Collection\Collection $collection */
$collection = Collection::new([1, 2, 3])
    ->append([4, 5, 6, 7, 8, 9])
    ->map(static fn ($v): int => $v * 10)
    ->filter(static fn ($v): bool => 0 === $v % 20);
    
$collection->toArray();  // [20, 40, 60, 80]
$collection->drop(1)     // [40, 60, 80]
           ->take(2)     // [40, 60]
           ->slice(1, 1) // [60]
           ->toArray();  // [60]

Credits

Thank you

Thank you for freely sharing your knowledge, insight and free time with me. I am grateful for your help and support.

Changelog

Please see CHANGELOG.md for more information on what has changed recently.

License

Please see LICENSE for more information on the license that applies to this project.

Security

Please see SECURITY.md for more information on security disclosure process.