source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Utils/ListExtensions.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 7 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 5.4 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace HeuristicLab.BioBoost.Utils {
5  public static class EnumerableExtensions {
6    public static IEnumerable<Tuple<T1, T2>> Zip<T1, T2>(IEnumerable<T1> e1, IEnumerable<T2> e2) {
7      var it1 = e1.GetEnumerator();
8      var it2 = e2.GetEnumerator();
9      while (it1.MoveNext() && it2.MoveNext()) {
10        yield return new Tuple<T1, T2>(it1.Current, it2.Current);
11      }
12    }
13    public static IEnumerable<Tuple<T1, T2, T3>> Zip<T1, T2, T3>(IEnumerable<T1> e1, IEnumerable<T2> e2, IEnumerable<T3> e3) {
14      var it1 = e1.GetEnumerator();
15      var it2 = e2.GetEnumerator();
16      var it3 = e3.GetEnumerator();
17      while (it1.MoveNext() && it2.MoveNext() && it3.MoveNext()) {
18        yield return new Tuple<T1, T2, T3>(it1.Current, it2.Current, it3.Current);
19      }
20      if (it1.MoveNext() || it2.MoveNext() || it3.MoveNext())
21        throw new InvalidOperationException("Iterators have different lengths");
22    }
23    public static IEnumerable<Tuple<T1, T2, T3, T4>> Zip<T1, T2, T3, T4>(IEnumerable<T1> e1, IEnumerable<T2> e2, IEnumerable<T3> e3, IEnumerable<T4> e4) {
24      var it1 = e1.GetEnumerator();
25      var it2 = e2.GetEnumerator();
26      var it3 = e3.GetEnumerator();
27      var it4 = e4.GetEnumerator();
28      while (it1.MoveNext() && it2.MoveNext() && it3.MoveNext() && it4.MoveNext()) {
29        yield return new Tuple<T1, T2, T3, T4>(it1.Current, it2.Current, it3.Current, it4.Current);
30      }
31      if (it1.MoveNext() || it2.MoveNext() || it3.MoveNext() || it4.MoveNext())
32        throw new InvalidOperationException("Iterators have different lengths");
33    }
34    public static IEnumerable<Tuple<T1, T2, T3, T4, T5>> Zip<T1, T2, T3, T4, T5>(IEnumerable<T1> e1, IEnumerable<T2> e2, IEnumerable<T3> e3, IEnumerable<T4> e4, IEnumerable<T5> e5) {
35      var it1 = e1.GetEnumerator();
36      var it2 = e2.GetEnumerator();
37      var it3 = e3.GetEnumerator();
38      var it4 = e4.GetEnumerator();
39      var it5 = e5.GetEnumerator();
40      while (it1.MoveNext() && it2.MoveNext() && it3.MoveNext() && it4.MoveNext() && it5.MoveNext()) {
41        yield return new Tuple<T1, T2, T3, T4, T5>(it1.Current, it2.Current, it3.Current, it4.Current, it5.Current);
42      }
43      if (it1.MoveNext() || it2.MoveNext() || it3.MoveNext() || it4.MoveNext() || it5.MoveNext())
44        throw new InvalidOperationException("Iterators have different lengths");
45    }
46    public static IEnumerable<Tuple<T1, T2, T3, T4, T5, T6>> Zip<T1, T2, T3, T4, T5, T6>(IEnumerable<T1> e1, IEnumerable<T2> e2, IEnumerable<T3> e3, IEnumerable<T4> e4, IEnumerable<T5> e5, IEnumerable<T6> e6) {
47      var it1 = e1.GetEnumerator();
48      var it2 = e2.GetEnumerator();
49      var it3 = e3.GetEnumerator();
50      var it4 = e4.GetEnumerator();
51      var it5 = e5.GetEnumerator();
52      var it6 = e6.GetEnumerator();
53      while (it1.MoveNext() && it2.MoveNext() && it3.MoveNext() && it4.MoveNext() && it5.MoveNext() && it6.MoveNext()) {
54        yield return new Tuple<T1, T2, T3, T4, T5, T6>(it1.Current, it2.Current, it3.Current, it4.Current, it5.Current, it6.Current);
55      }
56      if (it1.MoveNext() || it2.MoveNext() || it3.MoveNext() || it4.MoveNext() || it5.MoveNext() || it6.MoveNext())
57        throw new InvalidOperationException("Iterators have different lengths");
58    }
59    public static IEnumerable<Tuple<T1, T2, T3, T4, T5, T6, T7>> Zip<T1, T2, T3, T4, T5, T6, T7>(IEnumerable<T1> e1, IEnumerable<T2> e2, IEnumerable<T3> e3, IEnumerable<T4> e4, IEnumerable<T5> e5, IEnumerable<T6> e6, IEnumerable<T7> e7) {
60      var it1 = e1.GetEnumerator();
61      var it2 = e2.GetEnumerator();
62      var it3 = e3.GetEnumerator();
63      var it4 = e4.GetEnumerator();
64      var it5 = e5.GetEnumerator();
65      var it6 = e6.GetEnumerator();
66      var it7 = e7.GetEnumerator();
67      while (it1.MoveNext() && it2.MoveNext() && it3.MoveNext() && it4.MoveNext() && it5.MoveNext() && it6.MoveNext() && it7.MoveNext()) {
68        yield return new Tuple<T1, T2, T3, T4, T5, T6, T7>(it1.Current, it2.Current, it3.Current, it4.Current, it5.Current, it6.Current, it7.Current);
69      }
70      if (it1.MoveNext() || it2.MoveNext() || it3.MoveNext() || it4.MoveNext() || it5.MoveNext() || it6.MoveNext() || it7.MoveNext())
71        throw new InvalidOperationException("Iterators have different lengths");
72    }
73    public static IEnumerable<Tuple<T1, T2, T3, T4, T5, T6, T7, T8>> Zip<T1, T2, T3, T4, T5, T6, T7, T8>(IEnumerable<T1> e1, IEnumerable<T2> e2, IEnumerable<T3> e3, IEnumerable<T4> e4, IEnumerable<T5> e5, IEnumerable<T6> e6, IEnumerable<T7> e7, IEnumerable<T8> e8) {
74      var it1 = e1.GetEnumerator();
75      var it2 = e2.GetEnumerator();
76      var it3 = e3.GetEnumerator();
77      var it4 = e4.GetEnumerator();
78      var it5 = e5.GetEnumerator();
79      var it6 = e6.GetEnumerator();
80      var it7 = e7.GetEnumerator();
81      var it8 = e8.GetEnumerator();
82      while (it1.MoveNext() && it2.MoveNext() && it3.MoveNext() && it4.MoveNext() && it5.MoveNext() && it6.MoveNext() && it7.MoveNext() && it8.MoveNext()) {
83        yield return new Tuple<T1, T2, T3, T4, T5, T6, T7, T8>(it1.Current, it2.Current, it3.Current, it4.Current, it5.Current, it6.Current, it7.Current, it8.Current);
84      }
85      if (it1.MoveNext() || it2.MoveNext() || it3.MoveNext() || it4.MoveNext() || it5.MoveNext() || it6.MoveNext() || it7.MoveNext() || it8.MoveNext())
86        throw new InvalidOperationException("Iterators have different lengths");
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.