PHP code example of phpfn / curry

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

    

phpfn / curry example snippets





$fn = \curry(function($a, $b) { return $a + $b; });

$fn(3);      // ($a = 3) + ($b = ?)
$fn(3)(4);   // ($a = 3) + ($b = 4)

$fn = \rcurry(function($a, $b) { return $a + $b; });

$fn(3);      // ($a = ?) + ($b = 3)
$fn(3)(4);   // ($a = 4) + ($b = 3)

$fn = \curry(function($a, $b, $c) { return $a + $b * $c; });

$fn = $fn(_, 3, 4); // ($a = ?)  + ($b = 3) * ($c = 4)
echo  $fn(42);      // ($a = 42) + ($b = 3) * ($c = 4)

$fn = \curry(function($a, $b, $c) { return $a + $b * $c; });

$fn = $fn(_, 3, _); // ($a = ?)  + ($b = 3) * ($c = ?)
$fn->lcurry(42);    // ($a = 42) + ($b = 3) * ($c = ?)
$fn->rcurry(23);    // ($a = ?)  + ($b = 3) * ($c = 23)

$fn = \curry(function($a, $b, $c) { return $a + $b * $c; });

$sum  = $fn(7, 9);    // 7 + 9 * ?
$sum(6);              // 7 + 9 * 6 

$mul  = $fn(_, 7, 9); // ? + 7 * 9
$mul(6);              // 6 + 7 * 9

$test = $fn(_, 7, _); // ? + 7 * ?
$test(6);             // 6 + 7 * ? 

$test = $fn(_, 7);    // ? + 7 * ?
$test->rcurry(6);     // ? + 7 * 6