reimplemented calculate in terms of foldLeft