Skip to content

Instantly share code, notes, and snippets.

@rossmurray
Created March 16, 2014 20:25
Show Gist options
  • Save rossmurray/9589382 to your computer and use it in GitHub Desktop.
Save rossmurray/9589382 to your computer and use it in GitHub Desktop.
public static IEnumerable<IEnumerable<T>> Window<T>(this IEnumerable<T> source, int size)
{
if(size < 2) return source.Select(x => new[]{x});
return source.Zip(source.Skip(1).Window(size - 1), (a,b) => new[]{a}.Concat(b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment