PHPackages                             ustream/option - 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. ustream/option

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

ustream/option
==============

0.1.0(13y ago)8961MITPHPPHP &gt;=5.3.0

Since Mar 11Pushed 12y ago30 watchersCompare

[ Source](https://github.com/ustream/option)[ Packagist](https://packagist.org/packages/ustream/option)[ Docs](http://github.com/ustream/option)[ RSS](/packages/ustream-option/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (1)

Ustream Option monad [![Build Status](https://camo.githubusercontent.com/41391c93ea2e97a011f8679a033926f383d1da47900d0156e9fd5e45c6b76013/68747470733a2f2f7472617669732d63692e6f72672f7573747265616d2f6f7074696f6e2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/ustream/option)
=============================================================================================================================================================================================================================================================================================

[](#ustream-option-monad-)

This is a PHP interpretation of the [Option type](http://en.wikipedia.org/wiki/Option_type) with [monadic](http://en.wikipedia.org/wiki/Monads_in_functional_programming) structure. We beleive that the tests document the behavior and even though the implementation is similar to [php-option](https://github.com/schmittjoh/php-option) there are some important differences we need to highlight.

### There is *apply* instead of *map* and *flatMap*

[](#there-is-apply-instead-of-map-and-flatmap)

We found it useful, that the monadic computation may decide to return with an arbitrary type, that will be converted to an *Option* if necessary.

The rules for `Some::apply` is as follows:

- If the return type is not an *Option* it will be wrapped in *Some*
- If there is no return value (actually the return value is null) it will be translated to *None*
- If the return type is an Option it will be passed through (the same as for *flatMap*)

### Examples

[](#examples)

Wrapping a non *Option* type:

```
$result = someMethodReturningAnOptionalString($params)
	->apply(
		function ($result) {
			return $result . ' is a string!';
		})
	->getOrElse('default');
```

No need to explicitly return with *None*:

```
$module = $dataMaybe
    ->apply(
		function ($data) {
			if (isset($data['moduleConfig'])) {
				if (count($data['moduleConfig']) == 1) {
					return key($data['moduleConfig']);
				} elseif (count($data['moduleConfig']) > 1) {
					return 'full';
				}
			}
		}
	)
	->getOrElse('unknown');
```

### There is *otherwise* instead of *orElse* with *LazyOption*

[](#there-is-otherwise-instead-of-orelse-with-lazyoption)

We use `None::otherwise` as the mirror of `Some::apply`.

### Examples

[](#examples-1)

Combining apply and otherwise:

```
header(
    locate($_SERVER["DOCUMENT_URI"])
		->apply(
			function ($location) {
				statsdIncrement('302');
				return 'Location: ' . $location;
			}
		)
		->otherwise(
			function () {
				statsdIncrement('404');
			}
		)
		->getOrElse("HTTP/1.0 404 Not Found")
);
```

Creating a chain of fallback functions:

```
return Ustream\Option\None::create()
    ->otherwise($this->ustreamPicture($userId, $size))
	->otherwise($this->facebookPictureFromSession($facebookNetwork, $isSecureAccess))
	->getOrElse($this->naPicture($size));
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

4859d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/431237?v=4)[Zsolt Takacs](/maintainers/oker1)[@oker1](https://github.com/oker1)

![](https://avatars.githubusercontent.com/u/682440?v=4)[Peter Wilcsinszky](/maintainers/pepov)[@pepov](https://github.com/pepov)

---

Top Contributors

[![oker1](https://avatars.githubusercontent.com/u/431237?v=4)](https://github.com/oker1 "oker1 (2 commits)")

---

Tags

optionmonad

### Embed Badge

![Health badge](/badges/ustream-option/health.svg)

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

###  Alternatives

[phpoption/phpoption

Option Type for PHP

2.7k566.1M169](/packages/phpoption-phpoption)[kartik-v/dependent-dropdown

A multi level dependent dropdown JQuery plugin that allows nested dependencies.

1825.1M3](/packages/kartik-v-dependent-dropdown)[chippyash/monad

Functional programming Monad support

2728.4k8](/packages/chippyash-monad)[marcosh/lamphpda

A collection of functional programming data structures

12214.1k4](/packages/marcosh-lamphpda)[fof/nightmode

Add a Night Mode option for your users to use on your Flarum forum

3781.9k2](/packages/fof-nightmode)[shrink0r/monatic

Fiddling with the monad concept in php

245.3k2](/packages/shrink0r-monatic)

PHPackages © 2026

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