using System; using System.Collections.Generic; using System.Linq; namespace MarkovGrams.Utilities { public static class LinqExtensions { public static void ForEach(this IEnumerable enumerable, Action action) { foreach (T item in enumerable) { action(item); } } public static T ShiftAt(this List list, int index) { T item = list[index]; list.RemoveAt(index); return item; } public static int CountCharInstances(this string str, char[] targets) { int result = 0; for (int i = 0; i < str.Length; i++) { for (int t = 0; t < targets.Length; t++) if (str[i] == targets[t]) result++; } return result; } public static bool StartsWithFast(this string str, string target) { if (str.Length < target.Length) return false; return str.Substring(0, target.Length) == target; } } }