@@ -11,6 +11,7 @@ import (
1111 "github.com/go-task/task/v3/internal/execext"
1212 "github.com/go-task/task/v3/internal/filepathext"
1313 "github.com/go-task/task/v3/internal/fingerprint"
14+ "github.com/go-task/task/v3/internal/omap"
1415 "github.com/go-task/task/v3/internal/templater"
1516 "github.com/go-task/task/v3/taskfile/ast"
1617)
@@ -272,7 +273,7 @@ func itemsFromFor(
272273 var keys []string // The list of keys to loop over (only if looping over a map)
273274 var values []any // The list of values to loop over
274275 // Get the list from a matrix
275- if f .Matrix != nil {
276+ if f .Matrix . Len () != 0 {
276277 return asAnySlice (product (f .Matrix )), nil , nil
277278 }
278279 // Get the list from the explicit for list
@@ -328,24 +329,16 @@ func itemsFromFor(
328329}
329330
330331// product generates the cartesian product of the input map of slices.
331- func product (inputMap map [string ] []any ) []map [string ]any {
332- if len ( inputMap ) == 0 {
332+ func product (inputMap omap. OrderedMap [string , []any ] ) []map [string ]any {
333+ if inputMap . Len ( ) == 0 {
333334 return nil
334335 }
335336
336- // Extract the keys and corresponding slices
337- keys := make ([]string , 0 , len (inputMap ))
338- slices := make ([][]any , 0 , len (inputMap ))
339- for key , slice := range inputMap {
340- keys = append (keys , key )
341- slices = append (slices , slice )
342- }
343-
344337 // Start with an empty product result
345338 result := []map [string ]any {{}}
346339
347340 // Iterate over each slice in the slices
348- for i , slice := range slices {
341+ _ = inputMap . Range ( func ( key string , slice [] any ) error {
349342 var newResult []map [string ]any
350343
351344 // For each combination in the current result
@@ -358,14 +351,15 @@ func product(inputMap map[string][]any) []map[string]any {
358351 newComb [k ] = v
359352 }
360353 // Add the current item with the corresponding key
361- newComb [keys [ i ] ] = item
354+ newComb [key ] = item
362355 newResult = append (newResult , newComb )
363356 }
364357 }
365358
366359 // Update result with the new combinations
367360 result = newResult
368- }
361+ return nil
362+ })
369363
370364 return result
371365}
0 commit comments