示例#1
0
function lazy_sum($traversable)
{
    return lazy_reduce($traversable, function ($res, $value) {
        return $value + $res;
    }, 0);
}
示例#2
0
function lazy_count($traversable)
{
    return lazy_reduce($traversable, function ($prev) {
        return $prev + 1;
    }, 0);
}
示例#3
0
function lazy_product($traversable)
{
    return lazy_reduce($traversable, function ($res, $value) {
        return $value * $res;
    }, 1);
}
示例#4
0
function lazy_max($traversable)
{
    return lazy_if(lazy_empty($traversable), lazy_exception(new \DomainException("Cannot determine max for empty traversable")), lazy_reduce($traversable, function ($res, $value) {
        return $value > $res || $res === null ? $value : $res;
    }, null));
}