2 using System
.Collections
;
3 using System
.Collections
.Generic
;
5 namespace IEnumerableExtras
8 /// <see cref="IEnumerable{T}"/> map extension.
10 public static class EnumerableMap
13 /// Produce new instance of <see cref="IEnumerable{TResult}"/> by applying
14 /// predicate to each element in this instance of <see cref="IEnumerable"/>.
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
< TResult
>( this IEnumerable collection
, Func
<object, TResult
> predicate
)
22 foreach ( var item
in collection
)
24 yield return predicate( item
);
29 /// Produce new instance of <see cref="IEnumerable{TResult}"/> by applying
30 /// predicate to each element in this instance of <see cref="IEnumerable{T}"/>.
32 /// <typeparam name="T">This collection's item type.</typeparam>
33 /// <typeparam name="TResult">Resulting collection item type.</typeparam>
34 /// <param name="collection">This instance of <see cref="IEnumerable{T}"/>.</param>
35 /// <param name="predicate">Function returnting objects of type <typeparamref name="TResult"/> based on objects of type <typeparamref name="T"/>.</param>
36 /// <returns></returns>
37 public static IEnumerable
<TResult
> Map
< T
, TResult
>( this IEnumerable
<T
> collection
, Func
<T
, TResult
> predicate
)
39 foreach ( var item
in collection
)
41 yield return predicate( item
);
45 public static IEnumerable
<TResult
> Map
< T
, TResult
>( this IEnumerable
<T
> collection
, Func
<T
, int, TResult
> predicate
)
48 foreach ( var item
in collection
)
50 yield return predicate( item
, i
++ );