MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ reduce()

template<FieldArray Array>
template<typename Acc , typename Fn >
Acc MayaFlux::Kakshya::DataFieldTraversal< Array >::reduce ( Acc  init,
Fn &&  fn 
) const
inline

Fold all available elements into an accumulator.

Template Parameters
AccAccumulator type.
FnCallable returning the next accumulator from the current accumulator and a borrowed element.
Parameters
initInitial accumulator.
fnFold operation applied in element order.
Returns
Final accumulator.
Note
An index where at() returns disengaged is skipped entirely; fn is not invoked for it, not even with a default-constructed element.

Definition at line 188 of file DataFieldTraversal.hpp.

189 {
190 for (size_t i = 0; i < m_array->size(); ++i) {
191 if (auto element = m_array->at(i))
192 init = std::invoke(fn, std::move(init), *element);
193 }
194 return init;
195 }

References MayaFlux::Kakshya::DataFieldTraversal< Array >::m_array.