Extension method for padding a sequence

This commit is contained in:
Chris Cameron
2018-02-10 16:22:45 -05:00
parent 03e852fd2e
commit b6a1ce9bd2
2 changed files with 42 additions and 0 deletions

View File

@@ -472,6 +472,31 @@ namespace ICD.Common.Utils.Extensions
yield return item;
}
/// <summary>
/// Pads the given sequence to the given count size with default items.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <param name="count"></param>
/// <returns></returns>
[PublicAPI]
public static IEnumerable<T> PadRight<T>(this IEnumerable<T> extends, int count)
{
if (extends == null)
throw new ArgumentNullException("extends");
int index = 0;
foreach (T item in extends)
{
yield return item;
index++;
}
for (; index < count; index++)
yield return default(T);
}
/// <summary>
/// Default ordering for the items in the sequence.
/// </summary>