Add PhpOption support to Option::of

This commit is contained in:
2024-07-27 21:20:35 -04:00
parent 7837f4af17
commit 7d25b9ea28
4 changed files with 96 additions and 4 deletions

View File

@@ -82,8 +82,8 @@ readonly class Option
public static function of(mixed $value): self
{
return match (true) {
// TODO: can we do this check without requiring this package?
// $value instanceof PhpOption => $value->isDefined() ? self::Some($value->get()) : self::None(),
is_object($value) && is_a($value, 'PhpOption\Option') =>
$value->isDefined() ? self::Some($value->get()) : self::None(),
default => new self($value),
};
}