-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Linq
Milestone
Description
Summary
Two of the IEnumerable extension methods that I carry in my collection (we all have a personal collection of IEnumerable extension methods, am I right?) are Append and Prepend, for adding a single element to the end or beginning of a sequence respectively. Though not quite as common as concatenating sequences, I have been surprised at how often this need arises. Doing this inside of an expression today is not straightforward; the best equivalent that I have found is far from ideal:
sequence.Concat(Enumerable.Repeat(singleValue, 1))
I propose adding Prepend and Append extension methods to Enumerable to fill this need.
API
public static class Enumerable
{
public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T value);
public static IEnumerable<T> Prepend<T>(this IEnumerable<T> source, T value)
}
Usage
optionalValues.Prepend("<None>")
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Linq