compile a reducing function for an object/array