sawbona / morelinq

Automatically exported from code.google.com/p/morelinq
Apache License 2.0
0 stars 0 forks source link

MaxByOrDefault #96

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Currently, MaxBy will throw an exception if executed on an empty enumerable.  I 
would like a way to provide it with a default value to use, or have it use 
default(TSource).

Example usage:
var emptyEnumerable = Enumerable.Empty<Person>();
var result = emptyEnumerable.MaxByOrDefault(person => person.Age);
Assert.Equal(0, result);

result = emptyEnumerable.MaxBy(person => person.Age, 10);
Assert.Equal(10, result);

Original issue reported on code.google.com by mi...@zoltu.net on 8 Dec 2014 at 8:12