Exemplo n.º 1
0
    return array_slice($a, 0, $n);
}, 'cons' => function ($x, $y) {
    return merge([$x], $y);
}, 'snoc' => function ($x, $y) {
    return merge($y, [$x]);
}, 'echo_' => function ($x) {
    echo $x;
    return $x;
}, 'id' => function ($x) {
    return $x;
}, 'chain' => function ($x, $y, $z) {
    return $x($z, $y($z));
}, 'zip' => function ($arr1, $arr2) {
    return foldr(function ($acc, $val) use($arr1, $arr2) {
        $lookup = subscript($val);
        $el1 = $lookup($arr1);
        $el2 = $lookup($arr2);
        return merge($acc, [[$el1, $el2]]);
    }, [], keys($arr1));
}, 'dup' => function ($x) {
    return [$x, $x];
}, 'swap' => function ($arr) {
    return merge([$arr[1], $arr[0]], array_slice($arr, 2));
}, 'first' => function ($f, $arr) {
    return cons($f(subscript(0, $arr)), array_slice($arr, 1));
}, 'second' => function ($f) {
    return compose('swap', first($f), 'swap');
}, 'head' => function ($arr) {
    return $arr[0];
}, 'delay' => function ($f, $args, $_) {
    return call_user_func_array($f, $args);
}]);
Exemplo n.º 2
0
function f_or()
{
    return curry1(function ($x) {
        return foldr(l_or(), false, $x);
    }, func_get_args());
}