marvin255 / optional
Optional container for PHP.
Installs: 1 017
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=8.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- infection/infection: ^0.31
- phpunit/phpunit: ^12.0
- vimeo/psalm: ^6.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 */});