Added (array of array).Flatten extension.
[IEnumerableExtras.git] / C# / EnumerableFlatten.cs
blob8a2b5f61e7d602bed7f4a10fc7058f587685f715
1 using System.Collections.Generic;
3 namespace IEnumerableExtras
5 /// <summary>
6 /// Provides <see cref="IEnumerable{T}"/> with Flatten extension method.
7 /// </summary>
8 public static class EnumerableFlatten
10 /// <summary>
11 /// Flatten two-tier collection into one-tier collection.
12 /// </summary>
13 /// <typeparam name="T"></typeparam>
14 /// <param name="collection"></param>
15 /// <returns></returns>
16 public static IEnumerable<T> Flatten< T >( this IEnumerable<IEnumerable<T>> collection )
18 foreach ( var enumerable in collection )
20 if ( enumerable != null )
22 foreach ( var item in enumerable )
24 yield return item;