product generates the cartesian product of the input map of slices.
(matrix *ast.Matrix)
| 517 | |
| 518 | // product generates the cartesian product of the input map of slices. |
| 519 | func product(matrix *ast.Matrix) []map[string]any { |
| 520 | if matrix.Len() == 0 { |
| 521 | return nil |
| 522 | } |
| 523 | |
| 524 | // Start with an empty product result |
| 525 | result := []map[string]any{{}} |
| 526 | |
| 527 | // Iterate over each slice in the slices |
| 528 | for key, row := range matrix.All() { |
| 529 | var newResult []map[string]any |
| 530 | |
| 531 | // For each combination in the current result |
| 532 | for _, combination := range result { |
| 533 | // Append each element from the current slice to the combinations |
| 534 | for _, item := range row.Value { |
| 535 | newComb := make(map[string]any, len(combination)) |
| 536 | // Copy the existing combination |
| 537 | maps.Copy(newComb, combination) |
| 538 | // Add the current item with the corresponding key |
| 539 | newComb[key] = item |
| 540 | newResult = append(newResult, newComb) |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | // Update result with the new combinations |
| 545 | result = newResult |
| 546 | } |
| 547 | |
| 548 | return result |
| 549 | } |
no test coverage detected
searching dependent graphs…