wasSharp – Diff between revs 32 and 43
?pathlinks?
Rev 32 | Rev 43 | |||
---|---|---|---|---|
Line 36... | Line 36... | |||
36 | if (@case.Length % 2 != 0) |
36 | if (@case.Length % 2 != 0) |
|
37 | throw new ArgumentException("Pairs of predicates expected."); |
37 | throw new ArgumentException("Pairs of predicates expected."); |
|
Line 38... | Line 38... | |||
38 | |
38 | |
|
39 | try |
39 | try |
|
- | 40 | { |
||
40 | { |
41 | var enumerable = query as IList<T> ?? query.ToList(); |
|
41 | using (var iter = query.GetEnumerator()) |
42 | using (var iter = enumerable.GetEnumerator()) |
|
42 | { |
43 | { |
|
43 | while (iter.MoveNext()) |
44 | while (iter.MoveNext()) |
|
44 | { |
45 | { |
|
45 | for (var i = 0; i < @case.Length; i += 2) |
46 | for (var i = 0; i < @case.Length; i += 2) |
|
46 | { |
47 | { |
|
47 | if (@case[i].Invoke(iter.Current) && @case[i + 1].Invoke(iter.Current)) |
48 | if (@case[i].Invoke(iter.Current) && @case[i + 1].Invoke(iter.Current)) |
|
48 | throw new Exception(); |
49 | throw new Exception(); |
|
49 | } |
50 | } |
|
50 | } |
51 | } |
|
51 | } |
52 | } |
|
52 | @default.Invoke(query.Last()); |
53 | @default.Invoke(enumerable.Last()); |
|
53 | } |
54 | } |
|
54 | catch |
55 | catch |
|
55 | { |
56 | { |
|
56 | } |
57 | } |
|
Line 268... | Line 269... | |||
268 | { |
269 | { |
|
269 | var l = new List<T>(o); |
270 | var l = new List<T>(o); |
|
270 | var r = new List<T>(p); |
271 | var r = new List<T>(p); |
|
271 | return l.Count > r.Count |
272 | return l.Count > r.Count |
|
272 | ? l.Zip(r, (x, y) => x.Equals(y) ? default(T) : y) |
273 | ? l.Zip(r, (x, y) => x.Equals(y) ? default(T) : y) |
|
273 | .Concat(l.Skip(r.Count())) |
274 | .Concat(l.Skip(r.Count)) |
|
274 | .Where(q => q != null && !q.Equals(default(T))) |
275 | .Where(q => q != null && !q.Equals(default(T))) |
|
275 | : r.Zip(l, (x, y) => x.Equals(y) ? default(T) : y) |
276 | : r.Zip(l, (x, y) => x.Equals(y) ? default(T) : y) |
|
276 | .Concat(r.Skip(l.Count())) |
277 | .Concat(r.Skip(l.Count)) |
|
277 | .Where(q => q != null && !q.Equals(default(T))); |
278 | .Where(q => q != null && !q.Equals(default(T))); |
|
278 | } |
279 | } |
|
Line 279... | Line 280... | |||
279 | |
280 | |
|
280 | /// <summary> |
281 | /// <summary> |
|
Line 284... | Line 285... | |||
284 | /// <param name="o">the first sequence to remove from</param> |
285 | /// <param name="o">the first sequence to remove from</param> |
|
285 | /// <param name="p">the second sequence to remove</param> |
286 | /// <param name="p">the second sequence to remove</param> |
|
286 | /// <returns>the first sequence excluding the second sequence</returns> |
287 | /// <returns>the first sequence excluding the second sequence</returns> |
|
287 | public static IEnumerable<T> SequenceExcept<T>(this IEnumerable<T> a, IEnumerable<T> b) where T : IEquatable<T> |
288 | public static IEnumerable<T> SequenceExcept<T>(this IEnumerable<T> a, IEnumerable<T> b) where T : IEquatable<T> |
|
288 | { |
289 | { |
|
289 | var ea = a.GetEnumerator(); |
290 | using (var ea = a.GetEnumerator()) |
|
290 | var eb = b.GetEnumerator(); |
- | ||
291 | while (ea.MoveNext()) |
- | ||
292 | { |
291 | { |
|
- | 292 | using (var eb = b.GetEnumerator()) |
||
- | 293 | { |
||
- | 294 | while (ea.MoveNext()) |
||
- | 295 | { |
||
293 | if (eb.MoveNext() && ea.Current.Equals(eb.Current)) |
296 | if (eb.MoveNext() && ea.Current.Equals(eb.Current)) |
|
294 | continue; |
297 | continue; |
|
295 | yield return ea.Current; |
298 | yield return ea.Current; |
|
- | 299 | } |
||
- | 300 | } |
||
296 | } |
301 | } |
|
297 | } |
302 | } |
|
298 | } |
303 | } |
|
299 | } |
304 | } |