* Recursive function that is able to create a matrix of lists. * The algorithm is quite simple and recursively applies a map. * @example * map(lists[0], (item0) => map(lists[1], (item1) => map(lists[2], (...) => [item0, item1, ...])))
(lists: L.List<L.List<I>>, items: L.List<I> = [])
| 15 | * map(lists[0], (item0) => map(lists[1], (item1) => map(lists[2], (...) => [item0, item1, ...]))) |
| 16 | */ |
| 17 | function _matrix<I>(lists: L.List<L.List<I>>, items: L.List<I> = []) { |
| 18 | if (items.length === lists.length) return items |
| 19 | |
| 20 | return map(lists[items.length], (item) => _matrix(lists, [...items, item])) |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Creates the cross-product of a list of lists. |