Created
July 29, 2018 10:36
-
-
Save AmirOfir/d15c61f6a750d10e26e0ecd6bcf8896e to your computer and use it in GitHub Desktop.
ConditionalSelect c# apply Enumerable Select method on values, conditional on a predicate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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