Skip to content

phpninjas/Comprehensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

For Comprehensions

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("");

About

For comprehension objects for PHP

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages