This is very half-baked, but I'm capturing an idea I wrote in an empty buffer.
This provides a similar behavior to Rust's std::option::Option
enum which encapsulates a value either existing as it should as "Some" value, or being empty or "None".
There's also a convenience for pattern matching, though more would need to go into the typing with PHPStan docstrings to make it more dynamic. As it is now though, it's possible to act on a Some
or None
match with a closure for the items.
The same approach could be applied with pattern's like std::result::Result
that wraps something as a successful operation or "Ok" or an "Err"or.