Add type refinements for `Fp\Collection\filter`
klimick opened this issue · 0 comments
klimick commented
use function Fp\Collection\filter;
/**
* @psalm-return array<string, array>
*/
function getCollection(): array { return []; }
/**
* @psalm-type Shape = array{name: string, postcode: int}
* @psalm-assert-if-true Shape $shape
*/
function isValidShape(array $shape): bool
{
return array_key_exists("name", $shape) &&
array_key_exists("postcode", $shape) &&
is_int($shape["postcode"]);
}
/** @psalm-trace $result */
$result = filter(
getCollection(),
fn(array $v) => isValidShape($v)
);
$result
will be refined from array<string, array>
to array<string, array{name: string, postcode: int}>