package gw.currency uses gw.pl.currency.MonetaryAmount uses java.lang.Iterable uses java.math.BigDecimal @ReadOnly enhancement GWIterableMonetaryAmountSumCoreEnhancement : Iterable { /** * Return the average of the values of the target of the mapper argument, * which must all be of the same currency as specified. */ reified function average( currency : Currency, select:block(elt:T):MonetaryAmount) : MonetaryAmount { return this.sum(currency, \ elt -> select(elt) ) / (this.Count as BigDecimal) } /** * Sums up the values of the target of the mapper argument, * which must all be of the same currency as specified. */ function sum( currency : Currency, mapper(elt:T) : MonetaryAmount ) : MonetaryAmount { var sum = new MonetaryAmount(0, currency)//TODO: 0bd.ofCurrency(currency) for (elt in this) { sum = sum.add(mapper( elt )) } return sum } }