marvin255 / optional
Optional container for PHP.
v0.1.6
2024-06-08 13:08 UTC
Requires
- php: >=8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- infection/infection: ^0.27
- phpunit/phpunit: ^10.0
- vimeo/psalm: ^5.0
README
PHP implementation of Java's Optional object.
A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.
Installation
Install via composer:
composer req marvin255/optional
Usage
use Marvin255\Optional\Optional; $optional = Optional::of($input); if ($optional->isPresent()) { $value = $optional->get(); // do something }
With lambda
use Marvin255\Optional\Optional; Optional::of($input)->ifPresent(function ($item): void {/* do something */});