minimalcode / php-java-optional
Java9 Optional implementation for PHP
Installs: 3 148
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: >=5.5
Requires (Dev)
- phpunit/phpunit: 4.8.*
README
Php implementation of Java-9 Optional, with 'generics' support
Features
- Full 1:1 implementation of Java-9 Optional API
- Generic support (conceptually, obviously), for objects and primitives
OptionalBool
,OptionalFloat
,OptionalInt
,OptionalString
already available- Only 1 single class, optimized for performance
- Production ready
Usage
echo OptionalString::of('hello')->orElse('world');// echo 'hello' echo OptonalInt::ofNullable(null)->orElse(42);// echo 42
Generics
/** * @method Book get() * @method Book|null orElse($other) * @method Book orElseGet(callable $supplier) * @method Book orElseThrow(callable $exceptionSupplier) */ class OptionalBook extends AbstractOptional { /** * @inheritdoc */ protected function supports($value) { return $value instanceof Book; } } $book = new Book() $optBook = OptionalBook::of($book);
http://download.java.net/java/jdk9/docs/api/java/util/Optional.html
https://www.mkyong.com/java8/java-8-optional-in-depth/
http://blog.codefx.org/java/dev/java-9-optional/
http://iteratrlearning.com/java9/2016/09/05/java9-optional.html