Changeset 11309
 Timestamp:
 08/27/14 10:14:54 (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/sources/HeuristicLab.Common/3.3/EnumerableExtensions.cs
r11171 r11309 87 87 return result; 88 88 } 89 90 /// <summary> 91 /// Compute the nary cartesian product of arbitrarily many sequences: http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computingacartesianproductwithlinq.aspx 92 /// </summary> 93 /// <typeparam name="T">The type of the elements inside each sequence</typeparam> 94 /// <param name="sequences">The collection of sequences</param> 95 /// <returns>An enumerable sequence of all the possible combinations of elements</returns> 96 public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences) { 97 IEnumerable<IEnumerable<T>> result = new[] { Enumerable.Empty<T>() }; 98 return sequences.Aggregate(result, (current, s) => (from seq in current from item in s select seq.Concat(new[] { item }))); 99 } 89 100 } 90 101 }
Note: See TracChangeset
for help on using the changeset viewer.