tekord / php-option
Option object for PHP inspired by the Rust programming language
v0.2
2024-11-01 09:29 UTC
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^9.3
This package is not auto-updated.
Last update: 2024-11-01 09:38:41 UTC
README
TBD
Installation
Install the package via Composer:
composer require tekord/php-option
Usage
Example:
$o = Option::some(200); $value = $o->unwrap(); // -> 200 $o = Option::none(); $value = $o->unwrap(); // -> ERROR $o = Option::none(); $value = $o->unwrapOrDefault(50); // -> 50 $o = Option::none(); $value = $o->unwrapOrNull(); // -> null $o = Option::some("Hello"); $o->isSome(); // true $o->isNone(); // false $o = Option::none(); $o->isSome(); // false $o->isNone(); // true
Testing
composer test