Is your feature request related to a problem? Please describe.
Is is feasible to
add non-empty-array and non-empty-list support to the type system, such that:
the return Psl\Iter\first and other functions can be T and not T|null?
Describe the solution you'd like
I want to be able to do things like:
<?php
declare(strict_types=1);
use Psl;
class FooExtractor
{
/** @param list<Foo> $foos */
public function __invoke(array $foos): Foo
{
$foosFiltered = Vec\filter(
$foos,
function (Foo $foo): bool {
...
}
);
//assert $foosFiltered type is non-empty-list/array here.
//this will error as the return type is `T|null`
return Iter\first($foosFiltered);
}
}
Is there a better way to achieve what I'm trying to do?
first reported in https://github.com/azjezz/psl/issues/145 by @bendavies