PHP code example of nemorize / curried

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

    

nemorize / curried example snippets


use Nemorize\Curried\Curried;
$context = Curried::from(function ($foo, $bar) {
    return $foo . $bar;
});

use Nemorize\Curried\Curried;
$context = Curried::from(function ($foo, $bar) {
    return $foo . $bar;
})->takes(0)->takes(1);

use Nemorize\Curried\Curried;
$context = Curried::from(function ($foo, $bar, $baz) {
    return $foo . $bar . $baz;
})->takes(0)->takesRest();

use Nemorize\Curried\Curried;
$context = Curried::from(function ($foo, $bar) {
    return $foo . $bar;
})->takes(0)->withStatic(1)('bar');

use Nemorize\Curried\Curried;
$curried = Curried::from(function ($foo, $bar) {
    return $foo . $bar;
})->takes(0)->takes(1)->generate();
$curried('foo')('bar'); // 'foobar'

use Nemorize\Curried\Curried;
$map = Curried::from(array_map(...))
    ->takes(0)
    ->takes(1)
    ->generate();
$plusOneEach = $map(fn (int $x) => $x + 1);
$plusOneEach([1, 2, 3]); // [2, 3, 4]

use Nemorize\Curried\Curried;
$sum = Curried::from(array_reduce(...))
    ->takes(1)
    ->withStatic(0)(fn (int $x, int $y) => $x + $y)
    ->generate();
$sum([1, 2, 3]); // 6