jackmott / LinqFaster

Linq-like extension functions for Arrays, Span<T>, and List<T> that are faster and allocate less.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Enhancement] DefaultIfEmptyF should be implemented

Smurf-IV opened this issue · comments

Both versions of this to work with List<T>, Array[T], Span<T>, ReadOnlySpan<T> and IReadOnlyList<T>

If the source is null or empty, then default to creating an array so that max speed is maintained.

Should this also follow the pattern for the other "Fast" api's e.g WhereSelect
i.e.

public static int MaxOrDefault<T>(this IEnumerable<T> enumeration, Func<T, int> selector)
{
    return enumeration.Any() ? enumeration.Max(selector) : default(int);
}