Added generic reducer accepting a reducing function.