PHPackages                             mckayb/phantasy-types - 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. mckayb/phantasy-types

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

mckayb/phantasy-types
=====================

Sum Types and Product Types in PHP

v1.0.0(7y ago)523[1 issues](https://github.com/mckayb/phantasy-types/issues)MITPHPPHP &gt;=7.1

Since Jul 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/mckayb/phantasy-types)[ Packagist](https://packagist.org/packages/mckayb/phantasy-types)[ RSS](/packages/mckayb-phantasy-types/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

Phantasy Types [![CircleCI](https://camo.githubusercontent.com/7cf176ce04f36b667322331e3a269d2f2fb756b982fa71e44f8e3b2ed3528d13/68747470733a2f2f636972636c6563692e636f6d2f67682f6d636b6179622f7068616e746173792d74797065732e7376673f7374796c653d737667)](https://circleci.com/gh/mckayb/phantasy-types)[![Coverage Status](https://camo.githubusercontent.com/db8547ab69aa5e1c0c3c7ceea38fdffbfc37596d761eef1f4aca4ab99e5560fd/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d636b6179622f7068616e746173792d74797065732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/mckayb/phantasy-types)
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#phantasy-types-)

Library for creating Sum Types and Product Types in PHP

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

`composer require mckayb/phantasy-types`

### Usage

[](#usage)

#### Product Types

[](#product-types)

```
use function Phantasy\Types\product;

$Point3D = product('Point3D', ['x', 'y', 'z']);
echo $Point3D; // 'Point3D'

$a = $Point3D(1, 2, 3);

echo $a; // 'Point3D(1, 2, 3)'
$Point3D->scale = function ($n) {
    return $this->Point3D($n * $this->x, $n * $this->y, $n * $this->z);
};

/*
Could also do
$Point3D->scale = function ($n) use ($Point3D) {
    return $Point3D($n * $this->x, $n * $this->y, $n * $this->z);
};
*/

$b = $a->scale(2);
echo $b; // 'Point3D(2, 4, 6)'
```

#### Sum Types

[](#sum-types)

```
use function Phantasy\Types\sum;

$Option = sum('Option', [
    'Some' => ['x'],
    'None' => []
]);

$a = $Option->Some(1);
$b = $Option->None();

echo $a; // "Option.Some(1)"
echo $b; // "Option.None()"

$Option->map = function ($f) {
    return $this->cata([
        'Some' => function ($x) use ($f) {
            return $this->Some($f($x));
        },
        'None' => function () {
            return $this->None();
        }
    ]);
};

$c = $a->map(function ($x) {
    return $x + 1;
});

$d = $b->map(function ($x) {
    return $x + 1;
});

echo $c; // "Option.Some(2)"
echo $d; // "Option.None()"
```

Contributing
------------

[](#contributing)

Find a bug? Want to make any additions? Just create an issue or open up a pull request.

Inspiration
-----------

[](#inspiration)

- [Daggy](https://github.com/fantasyland/daggy)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~150 days

Total

5

Last Release

2634d ago

Major Versions

v0.3.0 → v1.0.02019-02-24

PHP version history (3 changes)v0.1.0PHP &gt;=7.0.0

v0.3.0PHP &gt;=7.0

v1.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/ded8ba6ab18cc39bc1796e8b9fd5bc8b6f3f5bd78180334e7bde2a65b937283d?d=identicon)[mckayb](/maintainers/mckayb)

---

Top Contributors

[![mckayb](https://avatars.githubusercontent.com/u/1355708?v=4)](https://github.com/mckayb "mckayb (13 commits)")

---

Tags

algebraic-data-typesfunctionalphantasyphantasy-typesphp

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mckayb-phantasy-types/health.svg)

```
[![Health](https://phpackages.com/badges/mckayb-phantasy-types/health.svg)](https://phpackages.com/packages/mckayb-phantasy-types)
```

###  Alternatives

[eyecatchup/webmaster-tools-data

An easy way to automate downloading of data tables from Google Webmaster Tools

1052.1k](/packages/eyecatchup-webmaster-tools-data)

PHPackages © 2026

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