PHPackages                             beezee/php-data - 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. beezee/php-data

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

beezee/php-data
===============

Algebraic data types with optics

03[1 issues](https://github.com/beezee/php-data/issues)PHP

Since Dec 28Pushed 7y ago2 watchersCompare

[ Source](https://github.com/beezee/php-data)[ Packagist](https://packagist.org/packages/beezee/php-data)[ RSS](/packages/beezee-php-data/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

php-data
========

[](#php-data)

API and underlying representation is still experimental.

This library defines Algebraic Data Types for PHP, with lenses and prisms for free.

```
require('./vendor/autoload.php');

class Pet extends Data\Data {
  static function constructors() {
    // eventually you would validate inputs here
    // php-data library to provide refined "types" before stable
    return [
      'Dog' => Widmogrod\Functional\identity,
      'Cat' => Widmogrod\Functional\identity,
      'Fish' => Widmogrod\Functional\identity
    ];
  }
}

php>  $dog = Pet::Dog(['fur' => 'brown']);
/* Pet Object
(
    [_k:Data\Data:private] => Dog
    [_d:Data\Data:private] => Array
        (
            [fur] => brown
        )

)
 */
php>  $cat = Pet::Cat(['fur' => 'tuxedo']);
/* Pet Object
(
    [_k:Data\Data:private] => Cat
    [_d:Data\Data:private] => Array
        (
            [fur] => tuxedo
        )

)
 */
php>  $fish = Pet::Fish(['color' => 'gold']);
/* Pet Object
(
    [_k:Data\Data:private] => Fish
    [_d:Data\Data:private] => Array
        (
            [color] => gold
        )

)
 */

$describe = [
  'Dog' => function($d) { return "The dog has {$d->fur} fur"; },
  'Cat' => function($c) { return "The cat has {$c->fur} fur"; },
  'Fish' => function($f) { return "The fish has {$f->color} scales"; }
];

php>  $dog->fold($describe);
/* The dog has brown fur */
php>  $cat->fold($describe);
/* The cat has tuxedo fur */
php>  $fish->fold($describe);
/* The fish has gold scales */

class Tree extends Data\Data {
  static function constructors() {
    return [
      'Branch' => Widmogrod\Functional\identity,
      'Leaf' => Widmogrod\Functional\identity
    ];
  }
}

$t = Tree::Branch(
  ['l' => Tree::Leaf(['value' => 1]),
   'r' => Tree::Branch([
      'l' => Tree::Leaf(['value' => 2]),
      'r' => Tree::Branch([
        'l' => Tree::Leaf(['value' => 3]),
        'r' => Tree::Leaf(['value' => 4])])
    ])]);

$toString = function($a) { return json_encode($a, JSON_PRETTY_PRINT); };

php>  $toString($t);
/* {
    "Tree::Branch": {
        "l": {
            "Tree::Leaf": {
                "value": 1
            }
        },
        "r": {
            "Tree::Branch": {
                "l": {
                    "Tree::Leaf": {
                        "value": 2
                    }
                },
                "r": {
                    "Tree::Branch": {
                        "l": {
                            "Tree::Leaf": {
                                "value": 3
                            }
                        },
                        "r": {
                            "Tree::Leaf": {
                                "value": 4
                            }
                        }
                    }
                }
            }
        }
    }
} */
php>  $t->lens()->view(['r', 'l'])->value;
/* 2 */
php>  $toString($t->lens()->set(['r', 'r', 'l', 'value'], 5));
/* {
    "Tree::Branch": {
        "l": {
            "Tree::Leaf": {
                "value": 1
            }
        },
        "r": {
            "Tree::Branch": {
                "l": {
                    "Tree::Leaf": {
                        "value": 2
                    }
                },
                "r": {
                    "Tree::Branch": {
                        "l": {
                            "Tree::Leaf": {
                                "value": 5
                            }
                        },
                        "r": {
                            "Tree::Leaf": {
                                "value": 4
                            }
                        }
                    }
                }
            }
        }
    }
} */
php>  $toString($t->lens()->modify(['r', 'r', 'r', 'value'], function($i) { return $i + 3; }));
/* {
    "Tree::Branch": {
        "l": {
            "Tree::Leaf": {
                "value": 1
            }
        },
        "r": {
            "Tree::Branch": {
                "l": {
                    "Tree::Leaf": {
                        "value": 2
                    }
                },
                "r": {
                    "Tree::Branch": {
                        "l": {
                            "Tree::Leaf": {
                                "value": 3
                            }
                        },
                        "r": {
                            "Tree::Leaf": {
                                "value": 7
                            }
                        }
                    }
                }
            }
        }
    }
} */
php>  $t->prism()->view(['r', 'l']);
/* Widmogrod\Monad\Maybe\Just Object
(
    [value:protected] => Tree Object
        (
            [_k:Data\Data:private] => Leaf
            [_d:Data\Data:private] => Array
                (
                    [value] => 2
                )

        )

)
 */
php>  $t->prism()->view(['r', 'l', 'l']);
/* Widmogrod\Monad\Maybe\Nothing Object
(
)
 */
```

More to come...

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![beezee](https://avatars.githubusercontent.com/u/682587?v=4)](https://github.com/beezee "beezee (18 commits)")

### Embed Badge

![Health badge](/badges/beezee-php-data/health.svg)

```
[![Health](https://phpackages.com/badges/beezee-php-data/health.svg)](https://phpackages.com/packages/beezee-php-data)
```

PHPackages © 2026

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