Custom aggregation function

It would be nice to be able to have a custom aggregation function besides the default sum, product and average implemented. This pull request adds this feature, along with automated tests.