Skip to content

Instantly share code, notes, and snippets.

@droyad
Created April 5, 2013 05:59
Show Gist options
  • Select an option

  • Save droyad/5316985 to your computer and use it in GitHub Desktop.

Select an option

Save droyad/5316985 to your computer and use it in GitHub Desktop.
public static void ForSingleMaybe<T>(this IEnumerable<T> sequence, Action<T> action)
{
using(var enumerator = sequence.GetEnumerator())
{
if(!enumerator.MoveNext())
return;
var item = enumerator.Current;
if(enumerator.MoveNext())
throw new InvalidOperationException("Sequence contains too many elements");
action(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment