IntArrayList
Raxos\Collection\IntArrayList is an ArrayList that only accepts integers. It implements ValidatedArrayListInterface and adds a sum helper.
php
class IntArrayList extends ArrayList implements ValidatedArrayListInterfaceMethods
sum
php
public function sum(): intReturns the sum of all items as an int.
validateItem
php
public static function validateItem(mixed $item): voidThrows a CollectionInvalidTypeException when the item is not an int. This runs for every item when the list is built through of().
Example
php
<?php
declare(strict_types=1);
use Raxos\Collection\IntArrayList;
$quantities = IntArrayList::of([3, 5, 8]);
$quantities->sum(); // 16See also the typed lists concept page.