MCPcopy
hub / github.com/go-task/task / product

Function product

variables.go:519–549  ·  view source on GitHub ↗

product generates the cartesian product of the input map of slices.

(matrix *ast.Matrix)

Source from the content-addressed store, hash-verified

517
518// product generates the cartesian product of the input map of slices.
519func 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}

Callers 1

itemsFromForFunction · 0.85

Calls 2

LenMethod · 0.45
AllMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…