示例#1
0
文件: S.php 项目: rkgladson/PHPixme
<?php

namespace PHPixme;

// -- Starling --
/**
 * Starling
 * This combinator takes two functions and applies the third across both.
 * The first operand must return a function, which will relieve the result of the second.
 * Useful for combining mappings of the same data together
 * @param callable $x
 * @param callable $y
 * @param mixed $z
 * @return \Closure|mixed
 * @sig Callable x -> Callable y -> z -> a
 */
function S($x = null, $y = null, $z = null)
{
    return call_user_func_array(__PRIVATE__::$instance[S], func_get_args());
}
const S = __NAMESPACE__ . '\\S';
__PRIVATE__::$instance[S] = __PRIVATE__::curryExactly3(function ($x, $y, $z) {
    __CONTRACT__::argIsACallable($x);
    __CONTRACT__::argIsACallable($y, 1);
    return call_user_func(__CONTRACT__::composedIsACallable(call_user_func($x, $z)), call_user_func($y, $z));
});
示例#2
0
<?php

namespace PHPixme;

/**
 * callWith
 * Produce a function that calls a function within a array or object
 * @param string $accessor
 * @param object|array $container
 * @return \Closure ($container) -> ((args) -> $container{[$accessor]}(...args))
 * @sig String -> Object|Array -> \Closure (*->x)
 */
function callWith($accessor = null, $container = null)
{
    return call_user_func_array(__PRIVATE__::$instance[callWith], func_get_args());
}
const callWith = __NAMESPACE__ . '\\callWith';
__PRIVATE__::$instance[callWith] = __PRIVATE__::curryExactly2(function ($accessor, $container) {
    $callable = __CONTRACT__::composedIsACallable(is_array($container) ? array_key_exists($accessor, $container) ? $container[$accessor] : null : [$container, $accessor]);
    return function () use($callable) {
        return call_user_func_array($callable, func_get_args());
    };
});