Error thrown for list of working employees
emanuelefirmani opened this issue · comments
Emanuele Firmani commented
If we pass to AverageYearsWorkedAtTheCompany an empty list or a list that contains only employees that still employed, method Average() will throw an exception, as it requires at least one element (
).I've solved it like this: https://github.com/emanuelefirmani/FunctionalProgrammingCSharp/blob/master/FunctorsMonads/WorkPermitCode.cs#L20
Emanuele Firmani commented
If we do not implement the requirement "Only employees that left", we could write:
return employees.Any() ? employees.Map(GetYearsWorked).Average() : new Option<double>();