ocramius / optional
This package is abandoned and no longer maintained.
The author suggests using the whsv26/functional package instead.
A port of java.util.Optional to PHP
1.0.0
2019-03-12 10:02 UTC
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
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.