2017 © Pedro Peláez
 

library phantasy-recursion-schemes

Common recursion schemes implemented in PHP

image

mckayb/phantasy-recursion-schemes

Common recursion schemes implemented in PHP

  • Thursday, February 15, 2018
  • by mckayb
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Phantasy Recursion Schemes CircleCICoverage Status

Common recursion schemes implemented in PHP., (*1)

Getting Started

Installation

composer require mckayb/phantasy-recursion-schemes, (*2)

Usage

// This comes from https://github.com/mckayb/phantasy-types
use function Phantasy\Types\sum;
use function Phantasy\Recursion\cata;

$LL = sum('LinkedList', [
    'Cons' => ['head', 'tail'],
    'Nil' => []
]);
$LL->map = function (callable $f) {
    return $this->cata([
        'Cons' => function ($head, $tail) use ($f) {
            return $this->Cons($head, $f($tail));
        },
        'Nil' => function () {
            return $this->Nil();
        }
    ]);
};
$LL->isNil = function () {
    return $this->cata([
        'Cons' => function ($head, $tail) {
            return false;
        },
        'Nil' => function () {
            return true;
        }
    ]);
};
$alg = function ($x) {
    return $x->isNil() ? 0 : $x->head + $x->tail;
};
$a = $LL->Cons(3, $LL->Cons(2, $LL->Cons(1, $LL->Nil())));
echo cata($alg, $a);
// 6

For more information, read the docs!, (*3)

What's Included

  • Catamorphisms, Anamorphisms, Hylomorphisms

Contributing

Find a bug? Want to make any additions? Just create an issue or open up a pull request., (*4)

Want more?

For other helpers not included in this repo, check out * Phantasy * Phantasy-PHP * Phantasy-Types, (*5)

The Versions

15/02 2018

dev-master

9999999-dev

Common recursion schemes implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

15/02 2018

v1.0

1.0.0.0

Common recursion schemes implemented in PHP

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires