MCPcopy
hub / github.com/cli/cli / Partition

Function Partition

pkg/cmdutil/args.go:67–77  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

65// returned, and any item that returns false for the predicate will be
66// included in the second slice returned.
67func 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.

Callers 3

AssetsFromArgsFunction · 0.92
createRunFunction · 0.92
TestPartitionFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestPartitionFunction · 0.68