Skip to content

Instantly share code, notes, and snippets.

@qerub
Created May 8, 2013 19:06
Show Gist options
  • Save qerub/5542796 to your computer and use it in GitHub Desktop.
Save qerub/5542796 to your computer and use it in GitHub Desktop.
Cons (i.e. prepend) for IEnumerable in C#
public static IEnumerable<T> Cons<T>(T head, IEnumerable<T> tail)
{
yield return head;
foreach (var t in tail) yield return t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment