Page MenuHomeDevCentral

WithCollection.php
No OneTemporary

WithCollection.php

<?php
namespace Keruald\OmniTools\Collections;
use OutOfRangeException;
trait WithCollection {
abstract function count () : int;
abstract function toArray() : array;
public function first () : mixed {
foreach ($this->toArray() as $item) {
return $item;
}
throw new OutOfRangeException("The collection is empty.");
}
public function firstOr (mixed $default) : mixed {
return match ($this->count()) {
0 => $default,
default => $this->first(),
};
}
}

File Metadata

Mime Type
text/x-php
Expires
Sun, Nov 16, 13:34 (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3153054
Default Alt Text
WithCollection.php (556 B)

Event Timeline