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
- 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()
, becauseempty
is a reserved PHP keyword- type-safety is not ensured at any time: generics have simply been stripped from the
Optional
implementation. 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
,Function
andSupplier
arguments 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.