combinations<T> method

Iterable<List<T>> combinations<T>(
  1. List<T> set
)

Implementation

Iterable<List<T>> combinations<T>(List<T> set) {
  final result = <List<T>>[[]];

  for (final element in set) {
    final newCombinations = <List<T>>[];
    for (final combination in result) {
      final ret = [element, ...combination];
      newCombinations.add(ret);
    }
    result.addAll(newCombinations);
  }

  return result;
}