Used 'materialize' and 'dematerialize' to implement the 'reduce' operator