protected IEnumerable<(string email, double totalCost)> CalculateTotalCostByCustomer(IEnumerable<Order> orders) { return orders .GroupBy(o => o.Email, StringComparer.CurrentCultureIgnoreCase) .OrderBy(g => g.Key, StringComparer.CurrentCultureIgnoreCase) .Select(orderGroup => { var totalCostInCents = orderGroup .SelectMany(o => o.Items) .Select(i => i.Quantity * ProductCatalog.FindProductByCode(i.ProductCode).PriceInCents) .Sum(); return (orderGroup.Key, (double) (totalCostInCents / 100)); }); }