cartesianProduct<T> static method

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

Computes the Cartesian product of a list of lists.

  • lists: A list of lists containing elements of type T.

Returns: An iterable containing lists representing the Cartesian product.

Implementation

static Iterable<List<T>> cartesianProduct<T>(List<List<T>> lists) {
  return lists.fold(<List<T>>[[]],
      (result, list) => result.expand((x) => list.map((y) => [...x, y])));
}