combinations<T> function

Iterable<List<T>> combinations<T>(
  1. List<List<T>> lists, [
  2. int index = 0,
  3. List<T>? prefix
])

Implementation

Iterable<List<T>> combinations<T>(
    List<List<T>> lists, [
      int index = 0,
      List<T>? prefix,
    ]) sync* {
  prefix ??= <T>[];

  if (lists.length == index) {
    yield prefix.toList();
  } else {
    for (final value in lists[index]) {
      yield* combinations(lists, index + 1, prefix..add(value));
      prefix.removeLast();
    }
  }
}