firstOrDefault default value that equates to false yields null
tankbob opened this issue · comments
Bob Vale commented
If you call firstOrDefault with a default value that equates to false then the return value will be null if the enumerable is empty.
testing.firstOrDefault(null, 0)
yields null
testing.firstOrDefault(null, false)
yiels null
This is because line at 1869 defaultValue = defaultValue || null
shouldn't it be defaultValue = (typeof(defaultValue) === 'undefined') ? null : defaultValue
That way passing in null
yields null
, passing in an undefined value yields null
everything else yields the supplied defaultValue
when the enumerable is empty
Bob Vale commented
also elementAtOrDefault and lastOrDefault suffer the same issue.