prototype of reduce function.