PHP Classes

File: compnents/optional/

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


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();})
For more information send a message to info at phpclasses dot org.