PHP code example of glider88 / php-trampoline

1. Go to this page and download the library: Download glider88/php-trampoline library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

glider88 / php-trampoline example snippets


/** @return Trampoline<int> */
function ackermann(int $n, int $m): Trampoline
{
    if ($n === 0) {
        return done($m + 1);
    }

    if ($m === 0) {
        return suspend(static fn() => ackermann($n - 1, 1));
    }

    return
        suspend(static fn() => ackermann($n, $m - 1))
            ->flatMap(
                static fn($res) => suspend(static fn() => ackermann($n - 1, $res))
            );
}

$this->assertEquals(7, run(ack(2, 2)));

shell
composer