19 using System.Collections.Generic;
23 namespace Lucene.Net.Search
25 public static class Extensions
28 public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(
this IEnumerable<IList<T>> sequences)
30 IEnumerable<IEnumerable<T>> emptyProduct =
new IEnumerable<T>[] { Enumerable.Empty<T>() };
31 return sequences.Aggregate(
33 (accumulator, sequence) =>
35 return accumulator.SelectMany(
37 (accseq, item) => accseq.Concat(
new T[] { item })
44 public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(
this IEnumerable<IEnumerable<T>> sequences)
46 IEnumerable<IEnumerable<T>> emptyProduct =
new IEnumerable<T>[] { Enumerable.Empty<T>() };
47 return sequences.Aggregate(
49 (accumulator, sequence) =>
51 return accumulator.SelectMany(
53 (accseq, item) => accseq.Concat(
new T[] { item })
61 static IEnumerable<IEnumerable<T>> CartesianProduct2<T>(
this IEnumerable<IEnumerable<T>> sequences)
63 IEnumerable<IEnumerable<T>> emptyProduct =
new[] { Enumerable.Empty<T>() };
64 return sequences.Aggregate(
66 (accumulator, sequence) =>
67 from accseq in accumulator
69 select accseq.Concat(
new[] { item }));