functional-csharp-code icon indicating copy to clipboard operation
functional-csharp-code copied to clipboard

Error thrown for list of working employees

Open emanuelefirmani opened this issue 6 years ago • 1 comments

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 (https://github.com/la-yumba/functional-csharp-code/blob/e151c288252c41ba9936e1e9d05431c587cd847a/Exercises/Chapter04/Solutions.cs#L67). I've solved it like this: https://github.com/emanuelefirmani/FunctionalProgrammingCSharp/blob/master/FunctorsMonads/WorkPermitCode.cs#L20

emanuelefirmani avatar Aug 13 '18 08:08 emanuelefirmani

If we do not implement the requirement "Only employees that left", we could write: return employees.Any() ? employees.Map(GetYearsWorked).Average() : new Option<double>();

emanuelefirmani avatar Aug 13 '18 08:08 emanuelefirmani