MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ArrayReduce

Function ArrayReduce

lib/base/array-script.cpp:141–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139}
140
141static Value ArrayReduce(const Function::Ptr& function)
142{
143 ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
144 Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
145 REQUIRE_NOT_NULL(self);
146 REQUIRE_NOT_NULL(function);
147
148 if (vframe->Sandboxed && !function->IsSideEffectFree())
149 BOOST_THROW_EXCEPTION(ScriptError("Reduce function must be side-effect free."));
150
151 if (self->GetLength() == 0)
152 return Empty;
153
154 Value result = self->Get(0);
155
156 ObjectLock olock(self);
157 for (size_t i = 1; i < self->GetLength(); i++) {
158 result = function->Invoke({ result, self->Get(i) });
159 }
160
161 return result;
162}
163
164static Array::Ptr ArrayFilter(const Function::Ptr& function)
165{

Callers

nothing calls this directly

Calls 5

ScriptErrorClass · 0.85
IsSideEffectFreeMethod · 0.80
GetLengthMethod · 0.45
GetMethod · 0.45
InvokeMethod · 0.45

Tested by

no test coverage detected