https://github.com/marvin255/optional
PHP implementation of Java's Optional object
https://github.com/marvin255/optional
optional php
Last synced: 4 months ago
JSON representation
PHP implementation of Java's Optional object
- Host: GitHub
- URL: https://github.com/marvin255/optional
- Owner: marvin255
- License: mit
- Created: 2022-06-30T20:22:30.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T21:56:16.000Z (over 1 year ago)
- Last Synced: 2024-03-25T00:42:07.692Z (over 1 year ago)
- Topics: optional, php
- Language: PHP
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Optional
[](https://packagist.org/packages/marvin255/optional)
[](https://packagist.org/packages/marvin255/optional)
[](https://packagist.org/packages/marvin255/optional)
[](https://github.com/marvin255/optional/actions?query=workflow%3A%22marvin255_optional%22)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:
```bash
composer req marvin255/optional
```## Usage
```php
use Marvin255\Optional\Optional;$optional = Optional::of($input);
if ($optional->isPresent()) {
$value = $optional->get();
// do something
}
```With lambda
```php
use Marvin255\Optional\Optional;Optional::of($input)->ifPresent(function ($item): void {/* do something */});
```