Changeset 11370
- Timestamp:
- 09/16/14 15:53:25 (10 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 11309,11347
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Common/3.3/EnumerableExtensions.cs
r11170 r11370 87 87 return result; 88 88 } 89 90 /// <summary> 91 /// Compute the n-ary cartesian product of arbitrarily many sequences: http://blogs.msdn.com/b/ericlippert/archive/2010/06/28/computing-a-cartesian-product-with-linq.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.Where(s => s.Any()).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.