public static <T> void filter(Collection<T> target, IPredicate<T> predicate) { Iterator<T> iter = target.iterator(); while (iter.hasNext()) { T element = iter.next(); if (!predicate.apply(element)) { iter.remove(); } } }
public static <TSource> TSource FirstOrDefault( Iterable<TSource> source, IPredicate<TSource> predicate) { for (TSource item : source) { if (predicate.Match(item)) { return item; } } return null; }
public static <TSource> Iterable<TSource> Where( Iterable<TSource> source, IPredicate<TSource> predicate) { ArrayList<TSource> list = new ArrayList<TSource>(); for (TSource item : source) { if (predicate.Match(item)) { list.add(item); } } return list; }