### Install prewk/option with Composer Source: https://github.com/prewk/option/blob/master/readme.md Use Composer to add the prewk/option library as a dependency to your PHP project. ```Shell composer require prewk/option ``` -------------------------------- ### Basic Usage of PHP Option Type Source: https://github.com/prewk/option/blob/master/readme.md Demonstrates importing the Option classes, defining functions that return Option types (Some or None), and using common methods like unwrapOr for fallback values, or for chaining options, and expect for handling None with exceptions. ```PHP 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!")); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.