Psalm
Get started
Documentation
Paid support
Plugins
Blog
GitHub
<?php /** * @template L * @template R * @psalm-inheritors Left<L>|Right<R> */ interface Either {} /** * @template R * @implements Either<empty, R> */ final class Right implements Either {} /** * @template L * @implements Either<L, empty> */ final class Left implements Either {} /** * @template L * @template R * * @param Either<L, R> $either * @return bool * * @psalm-assert-if-true Left<L> $either */ function isLeft(Either $either): bool { throw new RuntimeException('???'); } /** @var Either<int, string> $either */ $either = null; if (!isLeft($either)) { /** @psalm-trace $left */ $left = $either; } else { /** @psalm-trace $right */ $right = $either; }
Snippet created on May 31 2023 at 08:50 UTC
Settings
Get link