I have the following code that I'm trying to improve:
BigDecimal total = entity.getAssociate().stream().map(Associates::getPropertyA)
.reduce(BigDecimal.ZERO, BigDecimal::add);
total = entity.getAssociate().stream().map(Associates::getPropertyB)
.reduce(total, BigDecimal::add);
total = entity.getAssociate().stream().map(Associates::getPropertyC)
.reduce(total, BigDecimal::add);
total = entity.getAssociate().stream().map(Associates::getPropertyD)
.reduce(total, BigDecimal::add);
It works, but it really feels like there is a better way of doing this. Can anybody enlighten me on the matter?