private static IEnumerable<IEnumerable<T>> SplitEvery<T>(this IEnumerable<T> xs, int n)
{
return xs.Unfold(ys => ys.Take(n), ys => ys.Any(), ys => ys.Skip(n));
}
private static IEnumerable<T> Unfold<T>(this T x, Func<T, T> h, Func<T, bool> p, Func<T, T> t)
{
for (var i = x; p(i); i = t(i))
yield return h(i);
}
2 comments:
It's O(N^2), right? (Because of how Skip works.)
Yes, I think it's O(N^2).
Post a Comment