Minus one IEnumerable from IEnumerable - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Minus one IEnumerable from IEnumerable

Demo Code


using System;//from w  w  w.j a  v a 2  s . com
using System.Linq;
using System.Collections.Generic;

public class Main{
    public static IEnumerable<T> Minus<T> (this IEnumerable<T> source, IEnumerable<T> what, Comparer<T> comparer, Cloner<T> cloner)
      {
         var v = what.ToList ();
         foreach (var t in source)
            if (v.All (i => !comparer (t, i)))
               yield return cloner (t);
      }
    public static IEnumerable<T> Minus<T> (this IEnumerable<T> source, IEnumerable<T> what, Comparer<T> comparer)
      {
         var v = what.ToList ();
         foreach (var t in source)
            if (v.All (i => !comparer (t, i)))
               yield return t;
      }
}

Related Tutorials