2017 © Pedro Peláez
 

library comprehensions

image

phpninjas/comprehensions

  • Tuesday, December 8, 2015
  • by james.turner.phpninja@gmail.com
  • Repository
  • 1 Watchers
  • 0 Stars
  • 802 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

For Comprehensions

Installation

composer.json, (*1)

{
  "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., (*2)

$product = $entityManager->find('Product', "some identifier");

if ($product === null) {
    return $product->getName();   
}
return "";

becomes, (*3)

$product = Option($entityManager->find('Product', "some identifier"));
$name = $product->map(function($p){
  return $p->getName();
});

return $name->getOrElse("");

The Versions

08/12 2015

dev-master

9999999-dev

  Sources   Download

The Development Requires

07/01 2015

v0.1.0

0.1.0.0

  Sources   Download

The Development Requires