Skip to content

michaelpetri/php-generic-list

Repository files navigation

PHP Generic List

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