Swift:
/// Provides tools for generating string permutations from multiple lists.
class CombinatoricalUtils {
private(set) var result: [String] = []
/// Internal recursive function to generate permutations.
private func generatePermutationsHelper(_ lists: [[String]], _ result: inout [String], _ depth: Int, _ current: String) {
if depth == lists.count {
result.append(current)
return
}
for item in lists[depth] {
generatePermutationsHelper(lists, &result, depth + 1, current + item)
}
}
/// Public entry to generate permutations between nested string lists
func generatePermutations(_ lists: [[String]]) {
result.removeAll()
generatePermutationsHelper(lists, &result, 0, "")
}
/// Alternate version using variadic parameters (similar to Python's *args)
func generatePermutationsV2(_ lists: [String]...) {
generatePermutations(lists)
}
}