Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marvin255/optional
PHP implementation of Java's Optional object
https://github.com/marvin255/optional
optional php
Last synced: about 1 month 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 (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T21:56:16.000Z (10 months ago)
- Last Synced: 2024-03-25T00:42:07.692Z (8 months 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
[![Latest Stable Version](https://poser.pugx.org/marvin255/optional/v)](https://packagist.org/packages/marvin255/optional)
[![Total Downloads](https://poser.pugx.org/marvin255/optional/downloads)](https://packagist.org/packages/marvin255/optional)
[![License](https://poser.pugx.org/marvin255/optional/license)](https://packagist.org/packages/marvin255/optional)
[![Build Status](https://github.com/marvin255/optional/workflows/marvin255_optional/badge.svg)](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 */});
```