michaelpetri/php-generic-list

Basic generic list with psalm support

0.2.1 2023-09-28 08:54 UTC

README

Type Coverage Latest Stable Version License

Installation

composer require michaelpetri/php-generic-list 

Usage

ImmutableList::of(1, 2, 3, 4, 5)
    ->filter(
        static fn(int $i): bool => 0 === $i % 2
    )
    ->map(
        static fn(int $i): int => 2 ** $i
    )
    ->with(
        32
    )
    ->with(
        32
    )
    ->unique()
    ->each(
        static function (int $i): void { sprintf("\d\n", $i) }
    )

// Output:
// 4 
// 16
// 32

Available methods

  • map
  • filter
  • each
  • toArray