Copy paste extension method for your convenience.
public static void Fork<T>( this IEnumerable<T> source, Func<T, bool> pred, out IEnumerable<T> matches, out IEnumerable<T> nonMatches) { var groupedByMatching = source.ToLookup(pred); matches = groupedByMatching[true]; nonMatches = groupedByMatching[false]; }
Or using tuples in C # 7.0
public static (IEnumerable<T> matches, IEnumerable<T> nonMatches) Fork<T>( this IEnumerable<T> source, Func<T, bool> pred) { var groupedByMatching = source.ToLookup(pred); return (groupedByMatching[true], groupedByMatching[false]); }
Michael Fry May 03 '17 at 8:15 pm 2017-05-03 20:15
source share