mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
parent
a3815e4efd
commit
ee75094128
@ -708,8 +708,8 @@ Signature:
|
|||||||
function reduce(func);
|
function reduce(func);
|
||||||
|
|
||||||
Reduces the elements of the array into a single value by calling the provided
|
Reduces the elements of the array into a single value by calling the provided
|
||||||
function `func` as `func(a, b)` repeatedly where `a` is the previous result of
|
function `func` as `func(a, b)` repeatedly where `a` and `b` are elements of the array
|
||||||
function call (null initially) and `b` is an element of the array.
|
or results from previous function calls.
|
||||||
|
|
||||||
### <a id="array-filter"> Array#filter
|
### <a id="array-filter"> Array#filter
|
||||||
|
|
||||||
|
@ -172,14 +172,17 @@ static Value ArrayReduce(const Function::Ptr& function)
|
|||||||
if (vframe->Sandboxed && !function->IsSideEffectFree())
|
if (vframe->Sandboxed && !function->IsSideEffectFree())
|
||||||
BOOST_THROW_EXCEPTION(ScriptError("Reduce function must be side-effect free."));
|
BOOST_THROW_EXCEPTION(ScriptError("Reduce function must be side-effect free."));
|
||||||
|
|
||||||
Value result;
|
if (self->GetLength() == 0)
|
||||||
|
return Empty;
|
||||||
|
|
||||||
|
Value result = self->Get(0);
|
||||||
|
|
||||||
ObjectLock olock(self);
|
ObjectLock olock(self);
|
||||||
BOOST_FOREACH(const Value& item, self) {
|
for (size_t i = 1; i < self->GetLength(); i++) {
|
||||||
ScriptFrame uframe;
|
ScriptFrame uframe;
|
||||||
std::vector<Value> args;
|
std::vector<Value> args;
|
||||||
args.push_back(result);
|
args.push_back(result);
|
||||||
args.push_back(item);
|
args.push_back(self->Get(i));
|
||||||
result = function->Invoke(args);
|
result = function->Invoke(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user