Skip to content

Instantly share code, notes, and snippets.

@ibnuh
Created April 18, 2019 08:54
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 ibnuh/b6555c2cdf068164344bd83617333b7f to your computer and use it in GitHub Desktop.
Save ibnuh/b6555c2cdf068164344bd83617333b7f to your computer and use it in GitHub Desktop.
Conditional IEnumerable.Select
public static IEnumerable<TResult> SelectWhere<TSource, TResult>(
this IEnumerable<TSource> source,
Func<TSource, TResult> selector,
Func<TSource, bool> predicate)
{
foreach (TSource item in source)
if (predicate(item))
yield return selector(item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment