Implement arbitrary aggregation function