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, May 17, 19:08 (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3682056
Default Alt Text
WithCollection.php (556 B)

Event Timeline