cartesianProduct<T> static method

Iterable<List<T>> cartesianProduct<T>(
  1. List<List<T>> lists
)

Computes the Cartesian product of a list of lists.

Implementation

static Iterable<List<T>> cartesianProduct<T>(List<List<T>> lists) {
  try {
    Iterable<List<T>> result = [[]];
    for (final list in lists) {
      result = result.expand((x) => list.map((y) => [...x, y]));
    }
    return result;
  } catch (e) {
    rethrow;
  }
}