I have next very non-optimized code:
void Summarize(IEnumerable<Section> sections)
{
this.DateBegin = sections.Select(s => s.Date).Min();
this.DateEnd = sections.Select(s => s.Date).Max();
this.Income = sections.Where(s => s.IsIncome).Sum(r => r.Amount);
this.ExpenditureBank = sections.Where(s => s.IsExpenditureBank).Sum(r => r.Amount);
this.ExpenditureClient = sections.Where(s => s.IsExpenditureClient).Sum(r => r.Amount);
this.Expenditure = this.ExpenditureBank + this.ExpenditureClient;
}
How to rewrite such it using IEnumerable.Aggregate()
, if applicable?