PHP code example of wojciech.nawalaniec / phlambda
1. Go to this page and download the library: Download wojciech.nawalaniec/phlambda 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/ */
wojciech.nawalaniec / phlambda example snippets
use Wojciech\Phlambda as f;
f\all(f\above(2), [1, 2, 3, 4]);
use function Wojciech\Phlambda\{all, above};
all(above(2), [1, 2, 3, 4]);
use function Wojciech\Phlambda\map;
use const Wojciech\Phlambda\toString;
map(toString, [1, 2, 3]);
use function Wojciech\Phlambda\{_, below, concat};
use const Wojciech\Phlambda\toString;
_($someArray)
->filter(below(30))
->map(toString) // you can use constant which will be resolved as callable by PHP
->reduce(concat(), ''); // or you can call function without params because all functions all curried
// we can use reduce function normally like this:
$array = ['a', 'b', 'c'];
$result = reduce(\Wojciech\Phlambda\concat, '', $array); // $result = 'abc'
// and we can use it like currying function:
$concat = reduce(\Wojciech\Phlambda\concat, ''); // now it will return callback accepting last param from reduce - an array
$result = $concat($array); // $result = 'abc'