Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Where with a local function
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 Iterator();
IEnumerable<T> Iterator()
{
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
You can’t perform that action at this time.