Esempio n. 1
0
<?php

/**
 * Created by PhpStorm.
 * User: azder
 * Date: 24/08/2015
 * Time: 7:05
 */
error_reporting(E_ALL);
require_once '../src/fun.php';
function println($expression)
{
    print var_export($expression, true) . PHP_EOL;
}
use function F\circ;
use function F\curry;
$has_null = curry('F\\any', 'is_null');
$doesnt_have_null = circ('\\F\\not', $has_null);
println($has_null([1, 2, 3, 4, 5]));
// false
println($has_null([1, 2, 3, null, 4, 5]));
// true
println($doesnt_have_null([1, 2, 3, 4, 5]));
// true
println($doesnt_have_null([1, 2, 3, null, 4, 5]));
// false
Esempio n. 2
0
use function F\lcirc;
use function F\lcomp;
use function F\rcirc;
use function F\rcomp;
use function F\unr;
$plus = function ($a, $b) {
    return $a + $b;
};
$mul = function ($a, $b) {
    return $a * $b;
};
$twice = function ($a) {
    return [$a, $a];
};
$increase = curry($plus, 1);
$double = curry($mul, 2);
$rcomp = rcomp($double, $increase);
$rc = rcirc($double, $increase);
$lcomp = lcomp($double, $increase);
$lc = lcirc($double, $increase);
println($rcomp(4));
// = (4 + 1) * 2
println($rc(4));
// = (4 + 1) * 2
println($lcomp(4));
// = (4 * 2) + 1
println($lc(4));
// = (4 * 2) + 1
println($double($increase(1)));
// 4
println(call_user_func(rcirc($double, $increase), 1));