PHPackages                             hopr/result - 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. hopr/result

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

hopr/result
===========

Result type for PHP, as I like it do be.

1.1.2(11mo ago)0179MITPHP

Since Apr 16Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/AsymetricData/Hopr-Result)[ Packagist](https://packagist.org/packages/hopr/result)[ RSS](/packages/hopr-result/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (2)Versions (8)Used By (0)

🐇 Hopr\\Result
==============

[](#-hoprresult)

A PHP Result type drawing from Gleam, delivering essential functionality in a concise, efficient package.

Provides fundamental outcome handling with minimal overhead.

I just wanted a Result library with an API I find *natural*.

🚀 Key features
--------------

[](#-key-features)

### ✅ Fluent workflow with nice API

[](#-fluent-workflow-with-nice-api)

```
$result = ok(5)
    ->map(fn($x) => $x * 2)        // Ok(10)
    ->map(fn($x) => $x + 1);       // Ok(11)
```

### 🧩 `use` Gleam keyword for PHP

[](#-use-gleam-keyword-for-php)

Elegant destructuring and dependency injection:

```
$cat_result = ok(['name' => 'Luna', 'age' => 7])
    // Bind `name` to the returned value of the callable
    ->use('name', fn($data) =>
        isset($data['name']) ? ok($data['name']) : err('Missing name'))
    // Bind `age` to the returned value of the callable. `name` is accessible here.
    ->use('age', fn($data, $name) =>
        isset($data['age']) ? ok($data['age']) : err('Missing age'))
    // And mapWith the previous `use` extracted fields!
    ->mapWith(fn($data, $name, $age) =>
        new Cat(name: $name, age: $age));
```

### ⚡️ Zero-dependency

[](#️-zero-dependency)

Pure PHP with no external runtime dependencies. Lightweight, easy to read, easy to debug.

📦 Installation
--------------

[](#-installation)

```
composer require hopr/result
```

Usage
-----

[](#usage)

See `examples/` for more examples.

### Create results

[](#create-results)

```
use function Hopr\Result\{ok, err};

// You can also use Ok::of(42);
$success = ok(42);
// You can also use Error::of("...");
$failure = err("something went wrong");
```

### Chain transformations

[](#chain-transformations)

```
$result = ok(5)
    ->map(fn($x) => $x * 2)        // Ok(10)
    ->map(fn($x) => $x + 1);       // Ok(11)
```

#### Graceful error handling

[](#graceful-error-handling)

```
$result = err("bad input")
    ->map(fn($x) => $x * 2)           // Still err("bad input")
    ->mapErr(fn($e) => "Error: $e");  // err("Error: bad input")
```

### Safe unwrapping

[](#safe-unwrapping)

```
if ($result->isOk()) {
    $value = $result->unwrap();       // ✅ safe
} else {
    $value = $result->unwrapOr(0);    // fallback value
}
```

### Monadic binding

[](#monadic-binding)

```
$parseNumber = function(string $input) {
    return is_numeric($input)
        ? ok((int)$input)
        : err("Not a number");
};

$result = ok("42")->bind($parseNumber);  // Ok(42)
```

For more examples, check the interface documentation in `src/Result.php`.

The Hopr project
================

[](#the-hopr-project)

A set of PHP components exploring novel features and alternative design patterns that could enrich the language's standard library.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance50

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~29 days

Total

4

Last Release

355d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/95305150?v=4)[Cédric](/maintainers/AsymetricData)[@AsymetricData](https://github.com/AsymetricData)

---

Top Contributors

[![AsymetricData](https://avatars.githubusercontent.com/u/95305150?v=4)](https://github.com/AsymetricData "AsymetricData (17 commits)")

---

Tags

resultresultsmonad

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hopr-result/health.svg)

```
[![Health](https://phpackages.com/badges/hopr-result/health.svg)](https://phpackages.com/packages/hopr-result)
```

###  Alternatives

[marcosh/lamphpda

A collection of functional programming data structures

12214.5k4](/packages/marcosh-lamphpda)[chippyash/monad

Functional programming Monad support

2828.5k8](/packages/chippyash-monad)[shrink0r/monatic

Fiddling with the monad concept in php

245.3k2](/packages/shrink0r-monatic)[godbout/alfred-workflow-scriptfilter

Generate Alfred 3 or 4 Workflow Results in PHP with a laugh.

173.7k1](/packages/godbout-alfred-workflow-scriptfilter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
