crossJoin static method

List<List> crossJoin(
  1. Iterable<Iterable> lists
)

Cross joins the given lists, returning every possible combination.

Arr.crossJoin([[1, 2], ['a', 'b']]);
// [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]

Implementation

static List<List> crossJoin(Iterable<Iterable> lists) {
  var result = <List>[<dynamic>[]];
  for (final source in lists) {
    final next = <List>[];
    for (final accumulated in result) {
      for (final item in source) {
        next.add([...accumulated, item]);
      }
    }
    result = next;
  }
  return result;
}