wasSharp – Diff between revs 52 and 53

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 52 Rev 53
Line 6... Line 6...
6   6  
7 using System; 7 using System;
8 using System.Collections.Generic; 8 using System.Collections.Generic;
Line 9... Line 9...
9 using System.Linq; 9 using System.Linq;
10   10  
11 namespace wasSharp.Linq 11 namespace wasSharp.Lambda
12 { 12 {
13 public static class Extensions 13 public static class Extensions
14 { 14 {
Line 303... Line 303...
303 return true; 303 return true;
304 } 304 }
305 return false; 305 return false;
306 } 306 }
307 } 307 }
308   -  
309 /// <summary> -  
310 /// Sequentially removes all the elements from the first sequence that are in the second sequence -  
311 /// or all the elements from the second sequence that are in the first sequence. -  
312 /// </summary> -  
313 /// <typeparam name="T">the type o the collection</typeparam> -  
314 /// <param name="o">the first sequence to remove from</param> -  
315 /// <param name="p">the second sequence to remove</param> -  
316 /// <returns>the first sequence excluding the second sequence or the second sequence excluding the first sequence</returns> -  
317 public static IEnumerable<T> SequenceExceptAny<T>(this IEnumerable<T> o, IEnumerable<T> p) where T : IEquatable<T> -  
318 { -  
319 var l = new List<T>(o); -  
320 var r = new List<T>(p); -  
321 return l.Count > r.Count -  
322 ? l.Zip(r, (x, y) => x.Equals(y) ? default(T) : y) -  
323 .Concat(l.Skip(r.Count)) -  
324 .Where(q => q != null && !q.Equals(default(T))) -  
325 : r.Zip(l, (x, y) => x.Equals(y) ? default(T) : y) -  
326 .Concat(r.Skip(l.Count)) -  
327 .Where(q => q != null && !q.Equals(default(T))); -  
328 } -  
329   -  
330 /// <summary> -  
331 /// Sequentially removes all the elements from the first sequence that are in the second sequence. -  
332 /// </summary> -  
333 /// <typeparam name="T">the type o the collection</typeparam> -  
334 /// <param name="o">the first sequence to remove from</param> -  
335 /// <param name="p">the second sequence to remove</param> -  
336 /// <returns>the first sequence excluding the second sequence</returns> -  
337 public static IEnumerable<T> SequenceExcept<T>(this IEnumerable<T> a, IEnumerable<T> b) where T : IEquatable<T> -  
338 { -  
339 using (var ea = a.GetEnumerator()) -  
340 { -  
341 using (var eb = b.GetEnumerator()) -  
342 { -  
343 while (ea.MoveNext()) -  
344 { -  
345 if (eb.MoveNext() && ea.Current.Equals(eb.Current)) -  
346 continue; -  
347 yield return ea.Current; -  
348 } -  
349 } -  
350 } -  
351 } -  
352 } 308 }
353 } 309 }