2017 © Pedro Peláez
 

library optional

A library to reduce the code required for null-checking.

image

typedphp/optional

A library to reduce the code required for null-checking.

  • Monday, August 10, 2015
  • by assertchris
  • Repository
  • 4 Watchers
  • 38 Stars
  • 49 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 44 % Grown

The README.md

Optional

Build Status Code Quality Code Coverage Version License, (*1)

This library is inspired by the code of Johannes Schmitt and the writing of Igor Wiedler. It is intended to reduce the code required for null-checking. Part of TypedPHP., (*2)

Examples

<?php

require("vendor/autoload.php");

use TypedPHP\Optional\Optional;

class Foo
{
    public function hello()
    {
        return new Bar();
    }
}

class Bar
{
    public function world()
    {
        return "hello world";
    }
}

$optional = new Optional(new Foo());
$optional->hello()->world()->value(); // "hello world"
<?php

require("vendor/autoload.php");

use TypedPHP\Optional\None;

$none = new None();
$none->hello()->world()->value(); // null
<?php

require("vendor/autoload.php");

use TypedPHP\Optional\None;

$none = new None();
$none
    ->none(function() { print "none"; }); // "none" printed
    ->value(function($value) { print $value; }); // $value not printed

use TypedPHP\Optional\Optional;

$optional = new Optional("hello world");
$optional
    ->none(function() { print "none"; }); // "none" not printed
    ->value(function($value) { print $value; }); // "hello world" printed

Once an Optional method call returns an empty value, it is transformed into a None., (*3)

Installation

❯ composer require "typedphp/optional:*"

Testing

❯ composer create-project "typedphp/optional:*" .
❯ vendor/bin/phpunit

The Versions

10/08 2015

dev-master

9999999-dev https://github.com/typedphp/optional

A library to reduce the code required for null-checking.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

02/11 2014

0.2.1

0.2.1.0 https://github.com/typedphp/optional

A library to reduce the code required for null-checking.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

14/09 2014

0.2

0.2.0.0 https://github.com/typedphp/php-optional

A library to reduce the code required for null-checking.

  Sources   Download

MIT

The Development Requires

14/09 2014

0.1.4

0.1.4.0 https://github.com/typedphp/php-optional

A library to reduce the code required for null-checking.

  Sources   Download

MIT

The Development Requires

28/08 2014

0.1.3

0.1.3.0 https://github.com/typedphp/php-optional

A library to reduce the code required for null-checking.

  Sources   Download

MIT

The Development Requires

28/08 2014

0.1.2

0.1.2.0 https://github.com/typedphp/php-optional

A library to reduce the code required for null-checking.

  Sources   Download

MIT

The Development Requires