MCPcopy Create free account
hub / github.com/cli/cli / Partition

Function Partition

pkg/cmdutil/args.go:85–95  ·  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

83// returned, and any item that returns false for the predicate will be
84// included in the second slice returned.
85func Partition[T any](slice []T, predicate func(T) bool) ([]T, []T) {
86 var matching, nonMatching []T
87 for _, item := range slice {
88 if predicate(item) {
89 matching = append(matching, item)
90 } else {
91 nonMatching = append(nonMatching, item)
92 }
93 }
94 return matching, nonMatching
95}
96
97// GlobPaths expands a list of file patterns into a list of file paths.
98// 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