PHP Classes

File: compnents/optional/readme.md

Recommend this page to a friend!
  Classes of Uldis Nelsons  >  D3 System  >  compnents/optional/readme.md  >  Download  
File: compnents/optional/readme.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: D3 System
Framework to edit model data using CRUD interfaces
Author: By
Last change:
Date: 2 months ago
Size: 446 bytes
 

Contents

Class file image Download

Optional container

The purpose of the class is to provide type-level solution for representing optional values. Helps to get rid of null checks and if -> else depth.

$value = null;
if ($obj !== null) {
    $value = $obj->getValue();
} else {
    $value = "b";
}

can be replaced with

$value = Optional::ofNullable($obj)
                   ->map(function () { return $obj -> getValue();})
                   ->orElse("b");
For more information send a message to info at phpclasses dot org.