# LightqueryCollection#reduce
TIP
type GenericReducer<Acc = any, El = any> = (acc: Acc, el: El) => Acc;
type ElementReducer<R = any> = GenericReducer<R, Element>;
declare function reduce<Acc = any>(reducer: ElementReducer<Acc>, acc?: Acc): Acc|undefined;
Apply a functional fold over the set of matched results. This is especially useful when trying to do several collection manipulation in a row and you do not want to add more cyclomatic complexity.
const validationSettings = {
// [...]
};
const fields = Object.keys(validationSettings);
µ("#myForm :input")
.reduce((formBuilder, el) => {
if(el.name in fields)
formBuilder.addField(el);
return formBuilder;
}, new FormBuilder()) // here equivalent to `filter` then `each`
.build()
.validateOrFail(validationSettings)
.getAllAsObject();