Example #1
0
/**
 * liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
 *
 * @param callable $transformation
 * @param Applicative $fa
 * @param Applicative $fb
 *
 * @return Applicative|\Closure
 */
function liftA2(callable $transformation = null, Applicative $fa = null, Applicative $fb = null)
{
    return call_user_func_array(curryN(3, function (callable $transformation, Applicative $fa, Applicative $fb) {
        return $fa->map(function ($a) use($transformation) {
            return function ($b) use($a, $transformation) {
                return call_user_func($transformation, $a, $b);
            };
        })->ap($fb);
    }), func_get_args());
}