Skip to content

Instantly share code, notes, and snippets.

@AmirOfir
Created July 29, 2018 10:36
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 AmirOfir/d15c61f6a750d10e26e0ecd6bcf8896e to your computer and use it in GitHub Desktop.
Save AmirOfir/d15c61f6a750d10e26e0ecd6bcf8896e to your computer and use it in GitHub Desktop.
ConditionalSelect c# apply Enumerable Select method on values, conditional on a predicate
public static IEnumerable<TResult> ConditionalSelect<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, bool> predicate, Func<TSource, TResult> truthySelector, Func<TSource, TResult> falsySelector)
{
return source.Select(a => predicate(a) ? truthySelector(a) : falsySelector(a));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment