Anonymous avatar Anonymous committed 3520bb1 Draft

added List.Shuffle() and IEnumerable.ToString(seperator) extension methods to
Cineraria.Convenience

Comments (0)

Files changed (3)

Cineraria.Convenience/Cineraria.Convenience.csproj

     <Compile Include="ColorHelper.cs" />
     <Compile Include="ConversionExtensions.cs" />
     <Compile Include="EnumerableExtensions.cs" />
+    <Compile Include="ListExtensions.cs" />
     <Compile Include="MiscExtensions.cs" />
     <Compile Include="GlobalSuppressions.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

Cineraria.Convenience/EnumerableExtensions.cs

         {
             return enumerable.Select(it => function(it));
         }
+
+        /// <summary>
+        /// Concatenates the members of this sequence, using the specified
+        /// separator between each member.
+        /// </summary>
+        /// <typeparam name="T">Collection type.</typeparam>
+        /// <param name="enumerable">The enumerable.</param>
+        /// <param name="separator">
+        /// The string to insert between each member.
+        /// </param>
+        /// <returns>
+        /// The members of this sequence concatenated into a string using the
+        /// specified separator.
+        /// </returns>
+        public static string ToString<T>(
+            this IEnumerable<T> enumerable,
+            string separator)
+        {
+            return string.Join<T>(separator, enumerable);
+        }
     }
 }

Cineraria.Convenience/ListExtensions.cs

+namespace Cineraria.Convenience
+{
+    using System;
+    using System.Collections.Generic;
+
+    /// <summary>
+    /// Extensions for the <see cref="List&lt;T&gt;"/> class.
+    /// </summary>
+    public static class ListExtensions
+    {
+        /// <summary>
+        /// Shuffles this list in-place.
+        /// </summary>
+        /// <typeparam name="T">
+        /// The type of the elements stored in the list.
+        /// </typeparam>
+        /// <param name="list">The list to shuffle.</param>
+        public static void Shuffle<T>(this List<T> list)
+        {
+            Random rng = new Random();
+            int n = list.Count;
+            while (n > 1)
+            {
+                n--;
+                int k = rng.Next(n + 1);
+                T value = list[k];
+                list[k] = list[n];
+                list[n] = value;
+            }
+        }
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.