Partition takes a slice of any type T and separates it into two slices of the same type based on the provided predicate function. Any item that returns true for the predicate will be included in the first slice returned, and any item that returns false for the predicate will be included in the secon
(slice []T, predicate func(T) bool)
| 65 | // returned, and any item that returns false for the predicate will be |
| 66 | // included in the second slice returned. |
| 67 | func Partition[T any](slice []T, predicate func(T) bool) ([]T, []T) { |
| 68 | var matching, nonMatching []T |
| 69 | for _, item := range slice { |
| 70 | if predicate(item) { |
| 71 | matching = append(matching, item) |
| 72 | } else { |
| 73 | nonMatching = append(nonMatching, item) |
| 74 | } |
| 75 | } |
| 76 | return matching, nonMatching |
| 77 | } |
| 78 | |
| 79 | // GlobPaths expands a list of file patterns into a list of file paths. |
| 80 | // If no files match a pattern, that pattern will return an error. |
no outgoing calls