Idiomatic way to create n-ary cartesian product (combinations of several sets of parameters)
- 阅读更多 关于 Idiomatic way to create n-ary cartesian product (combinations of several sets of parameters)
问题 To create all possible combinations of two sets of parameters and perform an action on them, you can do: setOf(foo, bar, baz).forEach { a -> setOf(0, 1).forEach { b -> /* use a and b */ } } However, if you have (potentially many) more parameters, this quickly turns into a pyramid of doom: setOf(foo, bar, baz).forEach { a -> setOf(0, 1).forEach { b -> setOf(true, false, null).forEach { c -> setOf("Hello,", "World!").forEach { d -> /* use a, b, c and d */ } } } } You could write this similarly