ocramius / optional
A port of java.util.Optional to PHP
Installs: 263
Dependents: 0
Suggesters: 0
Security: 0
Stars: 24
Watchers: 2
Forks: 4
Open Issues: 9
pkg:composer/ocramius/optional
Requires
- php: ^7.3
Requires (Dev)
- doctrine/coding-standard: ^5.0
- infection/infection: ^0.12.2
- phpunit/phpunit: ^8.0.4
- squizlabs/php_codesniffer: ^3.4.0
- vimeo/psalm: ^3.1
- dev-master
- 1.0.0
- dev-dependabot/composer/phpunit/phpunit-tw-9.5.8
- dev-dependabot/composer/vimeo/psalm-tw-4.9
- dev-dependabot/composer/doctrine/coding-standard-tw-9.0
- dev-dependabot/composer/squizlabs/php_codesniffer-tw-3.6.0
- dev-dependabot/composer/infection/infection-tw-0.21.5
- dev-dependabot/add-v2-config-file
This package is auto-updated.
Last update: 2021-09-19 03:48:45 UTC
README
This package is a PHP port of the java.util.Optional class in the
OpenJDK libraries.
Currently maintained by Niklas Schöllhorn, taken over 3rd March, 2019
You can find the API of java.lang.Optional in the
Java 8 API docs.
Installation
composer require ocramius/optional
Differences with the Java implementation
Because of PHP's current limitations, I had to rewrite some bits of the Java implementation as follows:
Optional#empty()is namedOptional#newEmpty(), becauseemptyis a reserved PHP keyword- type-safety is not ensured at any time: generics have simply been stripped from the
Optionalimplementation. This may change in future, but I don't plan to do it right now. Optional#toString()is namedOptional#__toString()in accordance to PHP magic methods namingConsumer,Predicate,FunctionandSupplierarguments are simplycallable, for simplicity and flexibility.
License
Since this library is a direct port of the OpenJDK sources, I have to keep the original license in place, which is GPLv2 + ClassPath exceptions.