PHP code example of yuyat / curry

1. Go to this page and download the library: Download yuyat/curry 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/ */

    

yuyat / curry example snippets



use function yuyat\curry;

$sum = curry(function ($x, $y, $z) {
    reteurn $x + $y + $z;
});

echo $sum(1)->apply(2)->apply(3), PHP_EOL;
// => 6

echo $sum[1][2][3], PHP_EOL; // Ruby-like short syntax
// => 6


use function yuyat\curry;

$sum = curry(function (/* numbers to calculate sum */) {
    $result = 0;

    foreach (func_get_args() as $arg) {
        $result += $arg;
    }

    return $result;
}, 3);

echo $sum(1)->apply(2)->apply(3), PHP_EOL;
// => 6