This package is a PHP port of the java.util.Optional
class in the
OpenJDK libraries.
You can find the API of java.lang.Optional
in the
Java 8 API docs.
composer require ocramius/optional:dev-master
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.
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.