RandallFlagg / morelinq

Automatically exported from code.google.com/p/morelinq
Apache License 2.0
0 stars 0 forks source link

RemoveAll operator #62

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Removes all items matching a criteria ... 

 public static IEnumerable<T> RemoveAll<T>(this IEnumerable<T> items, Func<T, bool> match)
        {
            var list = items.ToList();
            for (int idx = 0; idx < list.Count(); idx++)
            {
                if (match(list[idx]))
                {
                    list.RemoveAt(idx);
                }
            }
            return list.AsEnumerable();
        }

Original issue reported on code.google.com by jal...@gmail.com on 14 Jan 2011 at 9:04

GoogleCodeExporter commented 9 years ago
This is already covered by the standard query operator Where that is part of 
LINQ. For example:

// Remove all odd numbers
var nums = Enumerable.Range(1, 100)
var evens = nums.Where(n => n % 2 != 0);

Original comment by azizatif on 20 Jan 2011 at 8:13

GoogleCodeExporter commented 9 years ago
Apart from being redundant and badly implemented ( O(n) in memory, O(n^2) in 
time and eagerly evaluating), it doesn't match the behavior of 
List<T>.RemoveAll(...) making it actively dangerous.

Original comment by CodeInCh...@quantentunnel.de on 2 Mar 2011 at 9:18