Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created July 20, 2017 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/0fc0d37d72b47f6fbb70543d17aef0c9 to your computer and use it in GitHub Desktop.
Save christiannagel/0fc0d37d72b47f6fbb70543d17aef0c9 to your computer and use it in GitHub Desktop.
Where with earlier error information using a separate method
public static IEnumerable<T> Where<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
return WhereImpl(source, predicate);
}
private static IEnumerable<T> WhereImpl<T>(IEnumerable<T> source, Func<T, bool> predicate)
{
foreach (T item in source)
{
if (predicate(item))
{
yield return item;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment