WingMan – Blame information for rev 32

Subversion Repositories:
Rev:
Rev Author Line No. Line
14 office 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4  
5 namespace WingMan.Utilities
6 {
7 public static class Extensions
8 {
9 /// <summary>
10 /// Sequentially removes all the elements from the first sequence that are in the second sequence.
11 /// </summary>
12 /// <typeparam name="T">the type o the collection</typeparam>
13 /// <param name="o">the first sequence to remove from</param>
14 /// <param name="p">the second sequence to remove</param>
15 /// <returns>the first sequence excluding the second sequence</returns>
16 public static IEnumerable<T> SequenceExcept<T>(this IEnumerable<T> a, IEnumerable<T> b) where T : IEquatable<T>
17 {
18 using (var ea = a.GetEnumerator())
19 {
20 using (var eb = b.GetEnumerator())
21 {
22 while (ea.MoveNext())
23 {
24 if (eb.MoveNext() && ea.Current.Equals(eb.Current))
25 continue;
26 yield return ea.Current;
27 }
28 }
29 }
30 }
31  
32 /// <summary>
33 /// Determines whether a sequence is contained within another sequence.
34 /// </summary>
35 /// <returns>true if and only if the first set is contained in the second set</returns>
36 /// <param name="a">The set to check</param>
37 /// <param name="b">The set to check against</param>
38 /// <typeparam name="T">the set type</typeparam>
39 public static bool SubsetEquals<T>(this IEnumerable<T> a, IEnumerable<T> b) where T : IEquatable<T>
40 {
41 return !a.OrderBy(s => s).SequenceExcept(b.OrderBy(s => s)).Any();
42 }
43 }
32 office 44 }