Adding C# solution.
[IEnumerableExtras.git] / C# / EnumerableMap.cs
blob7d3c0ac29ccc583f20698dfd546900cd99cc3d8c
1 using System;
2 using System.Collections.Generic;
4 namespace IEnumerableExtras
6 /// <summary>
7 /// <see cref="IEnumerable{T}"/> map extension.
8 /// </summary>
9 public static class EnumerableMap
11 /// <summary>
12 /// Produce new instance of <see cref="IEnumerable{TResult}"/> by applying
13 /// predicate to each element in this instance of <see cref="IEnumerable{T}"/>.
14 /// </summary>
15 /// <typeparam name="T">This collection's item type.</typeparam>
16 /// <typeparam name="TResult">Resulting collection item type.</typeparam>
17 /// <param name="collection">This instance of <see cref="IEnumerable{T}"/>.</param>
18 /// <param name="predicate">Function returnting objects of type <typeparamref name="TResult"/> based on objects of type <typeparamref name="T"/>.</param>
19 /// <returns></returns>
20 public static IEnumerable<TResult> Map< T, TResult >( this IEnumerable<T> collection, Func<T, TResult> predicate )
22 foreach ( var item in collection )
24 yield return predicate( item );