diff --git a/README.md b/README.md index 8643cd5..07d36e3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # Results [WIP] -Results is a PHP library that provides a set of helper functions and classes for handling optional values and results of operations. It is inspired by the [`Option`](https://doc.rust-lang.org/std/option/enum.Option.html) and [`Result`](https://doc.rust-lang.org/std/result/enum.Result.html) types in Rust. The implementation itself is based on the TypeScript implementation called [`ts-results`](https://github.com/vultix/ts-results). +Results is a PHP simple (dependency-free) library that provides a set of helper functions and classes for handling optional values and results of operations. +It is inspired by the [`Option`](https://doc.rust-lang.org/std/option/enum.Option.html) and [`Result`](https://doc.rust-lang.org/std/result/enum.Result.html) types in Rust. The implementation itself is based on the TypeScript implementation called [`ts-results`](https://github.com/vultix/ts-results). ## Installation -You can install the library via Composer: +You can install the library through Composer: ```bash composer require bosunski/results @@ -17,6 +18,8 @@ composer require bosunski/results The `Option` type represents an optional value: every `Option` is either `Some` and contains a value, or `None`, and does not. ```php +isSome()) { } else { // Handle the case where no user was found } + +// You can also do this +$user = $userOption->unwrap() // Throws error if null ``` Now, let's consider a scenario where we have a function that can either succeed or fail. We can use the `Result` type to handle this. ```php +isOk()) { $error = $result->unwrapErr(); // Handle the error } + +// You can also do this +$user = $result->unwrap() // Throws error if an error is present ``` In these examples, the `Option` and `Result` types provide a way to handle optional values and the results of operations in a safe and expressive manner. @@ -135,6 +152,8 @@ The `wrap` function is a utility function provided by the library. It is designe Here's an example of how you might use the wrap function: ```php +isOk()) { echo "Success: " . $result->unwrap(); @@ -159,12 +178,18 @@ In this example, `mightThrowException` is a function that might throw an excepti The `wrap` function provides a safe and expressive way to handle operations that can throw errors, allowing you to focus on your application logic rather than error handling when you don't need to. ## Contributing - -You can see the [Contributing] docs for more details +### Setting up the project +You can install development dependencies by running: +```shell +composer install +``` +### Running tests +```shell +composer run test +``` ## License This project is licensed under the [MIT License]. [MIT license]: LICENSE -[Contributing]: CONTRIBUTING.md \ No newline at end of file diff --git a/composer.json b/composer.json index 95423ce..167fd57 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ ], "license": "MIT", "require": { - "php": "^8.0" + "php": ">=8.0" }, "require-dev": { "phpstan/phpstan": "^1.10",