using System; using System.Collections.Generic; public static class Strain { public static IEnumerable Keep(this IEnumerable collection, Func predicate) { return ApplyPredicate(collection, predicate); } public static IEnumerable Discard(this IEnumerable collection, Func predicate) { return ApplyPredicate(collection, x => !predicate(x)); } private static IEnumerable ApplyPredicate(IEnumerable collection, Func predicate) { // could knock this down to a simple LINQ expression but restriction prevents that var filtered = new List(); foreach (var item in collection) { if (predicate(item)) filtered.Add(item); } return filtered; } }