The default values ββmust be constants, and the only constant value for the delegate is a null reference.
I suggest you use overload instead. Note that t => t not valid in any case, unless you know that there is a conversion from IEnumerable<R> to T that I cannot see anywhere.
In addition to the validity problem of the lambda expression, you can use the null coalescing operator:
IEnumerable<T> Chunk<T, R>(IEnumerable<R> src, int n, Func<IEnumerable<R>, T> action = null) { action = action ?? (t => t); ... }
... but it would be like abusing it, and you wonβt be able to determine if null was really from the caller who thought they were passing a non-zero value, and would rather you raise an ArgumentNullException .
EDIT: Also, note that your method is fundamentally problematic - repeating fragments will evaluate the original sequence several times (once per piece) to skip the desired amount. It would probably be better to write a method that every piece would read with impatience before returning. We have a similar method in MoreLINQ called Batch . Note that Batch has the overload specified here, and in this case t => t works, because the overload has fewer type parameters, so we know that the identity conversion is fine.
source share