Commits

rimmington  committed 1f7e7c7 Draft

added Map IEnumerable extension

  • Participants
  • Parent commits 0fd7d67

Comments (0)

Files changed (1)

File Cineraria.Convenience/EnumerableExtensions.cs

 
 namespace Cineraria.Convenience
 {
+    using System;
     using System.Collections.Generic;
     using System.Linq;
 
         public static IEnumerable<ElementIndex<T>> WithIndex<T>(
             this IEnumerable<T> enumerable)
         {
-            return enumerable.Select((e, i) => new ElementIndex<T> { Element = e, Index = i });
+            return enumerable.Select((e, i) =>
+                new ElementIndex<T> { Element = e, Index = i });
+        }
+
+        /// <summary>
+        /// Apply <paramref name="function"/> to every item of this sequence
+        /// and return a sequence of the results.
+        /// </summary>
+        /// <typeparam name="T">Collection type.</typeparam>
+        /// <typeparam name="TResult">The type of the result.</typeparam>
+        /// <param name="enumerable">The enumerable.</param>
+        /// <param name="function">The function to apply.</param>
+        /// <returns>
+        /// An enumerable containing the results of the function application.
+        /// </returns>
+        public static IEnumerable<TResult> Map<T, TResult>(
+            this IEnumerable<T> enumerable,
+            Func<T, TResult> function)
+        {
+            return enumerable.Select(it => function(it));
         }
     }
 }