2017 © Pedro Peláez
 

library option

Option object for PHP inspired by Rust

image

prewk/option

Option object for PHP inspired by Rust

  • Monday, March 19, 2018
  • by prewk
  • Repository
  • 1 Watchers
  • 3 Stars
  • 3,254 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 16 Versions
  • 7 % Grown

The README.md

PHP Option Object Build Status Coverage Status

A PHP implementation of Rust's Option type with roughly the same API., (*1)

Version information

Version 4.x.x requires PHP 8.1+. Make sure you match the versions for this and the Result library if you use both., (*2)

Installation

composer require prewk/option

Usage

use Prewk\Option;
use Prewk\Option\{Some, None};

function findSomething(): Option {
    // ...
    if ($foundSomething) {
        return new Some($thing);
    } else {
        return new None;
    }
}

function findSomethingElse(): Result {
    // ...
    if ($foundSomething) {
        return new Some($thing);
    } else {
        return new None;
    }
}

// Fallback to value
$value = findSomething()->unwrapOr(null);

// Fallback to option and throw an exception if both fail
$value = findSomething()->or(findSomethingElse())->unwrap();

// Throw custom exception on missing thing (None)
$value = findSomething()->expect(new Exception("Oh noes!"));

License

MIT & Apache 2.0, (*3)

The Versions

19/03 2018

dev-master

9999999-dev

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

19/03 2018

2.0.0

2.0.0.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

19/03 2018

dev-generics

dev-generics

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

24/02 2018

1.3.0

1.3.0.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

06/02 2018

1.2.1

1.2.1.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

06/02 2018

1.2.0

1.2.0.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

20/11 2017

1.1.2

1.1.2.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

18/11 2017

1.1.1

1.1.1.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

18/11 2017

1.1.0

1.1.0.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

04/09 2017

1.0.2

1.0.2.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

04/09 2017

1.0.1

1.0.1.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

31/07 2017

1.0.0

1.0.0.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

28/04 2017

0.0.5

0.0.5.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

28/04 2017

0.0.4

0.0.4.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Requires

 

The Development Requires

28/04 2017

0.0.3

0.0.3.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Development Requires

28/04 2017

0.0.1

0.0.1.0

Option object for PHP inspired by Rust

  Sources   Download

(MIT and Apache-2.0)

The Development Requires