PHPackages                             someniatko/result-type - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. someniatko/result-type

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

someniatko/result-type
======================

Functional-ish generic Result type: either Success or Error

1.6.0(4mo ago)63.7k↓52.1%1MITPHPPHP 8.2.\* || 8.3.\* || 8.4.\* || 8.5.\*CI passing

Since Apr 20Pushed 4mo ago3 watchersCompare

[ Source](https://github.com/someniatko/php-result-type)[ Packagist](https://packagist.org/packages/someniatko/result-type)[ RSS](/packages/someniatko-result-type/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (4)Versions (12)Used By (1)

someniatko/result-type
======================

[](#someniatkoresult-type)

Library representing a generic Result type with Success and Error states, made for aiding this functional programming pattern in PHP.

It is generically typed using Psalm annotations, so you are expected to use Psalm if you want typechecking of your code.

**Why using this library if `graham-campbell/result-type` exists?**
Unfortunately, there are several downsides of that library:

- while it's also typed with Psalm annotations, actually using and checking against them might be painful.
- it's coupled to the `phpoption/phpoption` library which unfortunately suffers from the same problem.
- there is no convenience method in Result interface which would allow getting either value from it.

Works best with [`someniatko/result-type-psalm-plugin`](https://packagist.org/packages/someniatko/result-type-psalm-plugin)!

Installation
------------

[](#installation)

This library requires PHP 8.2, 8.3, 8.4 or 8.5. You can install it via Composer:

```
composer install someniatko/result-type
```

Usage
-----

[](#usage)

See [`ResultInterface`](src/ResultInterface.php) for details.

Example:

```
