Code:
public static IEnumerable<T> Yield<T>(this T item) { yield return item; }
public static IEnumerable<T> Yield<T>(this T item) { yield return item; }
public static IEnumerable<IEnumerable<T>> TakeBy<T>(this IEnumerable<T> source, int count) { var grps = source.Select((val, i) => new { idx = i / count, val }).GroupBy(e => e.idx); return grps.Select(g => g.Select(e => e.val)); }
public static IEnumerable<IEnumerable<T>> Combine<T>(this IEnumerable<T> list, int k = 2, bool repetition = false) { for (int i = 0; i < list.Count(); i++) { T cur = list.Skip(i).First(); if (k == 1) { yield return cur.Yield(); } else { foreach (var res in list.Skip(i + (repetition ? 0 : 1)).Combine(k - 1, repetition)) { yield return res.Prepend(cur); } } } }