phpninjas / comprehensions
Installs: 812
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/phpninjas/comprehensions
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2025-10-07 09:11:18 UTC
README
Installation
composer.json
{ "require": { "phpninjas/comprehensions":"dev-master" } }
Options
Imagine if you're using Doctrine, and you don't know if attempting to find an object by id will result in an object or a null value. Thus you might want to wrap the object into an option. It will either be Some[DbObject] or None. However, you can still perform mapping operations on it as if it were going to be a DbObject. Thus you negate the need for null checks.
$product = $entityManager->find('Product', "some identifier"); if ($product === null) { return $product->getName(); } return "";
becomes
$product = Option($entityManager->find('Product', "some identifier")); $name = $product->map(function($p){ return $p->getName(); }); return $name->getOrElse("");