mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
17 lines
427 B
Go
17 lines
427 B
Go
package underscore
|
|
|
|
// Partition splits the slice into two slices: one whose elements all satisfy predicate
|
|
// and one whose elements all do not satisfy predicate.
|
|
func Partition[T any](values []T, predicate func(T) bool) ([]T, []T) {
|
|
keep := make([]T, 0)
|
|
reject := make([]T, 0)
|
|
|
|
for _, v := range values {
|
|
if predicate(v) {
|
|
keep = append(keep, v)
|
|
} else {
|
|
reject = append(reject, v)
|
|
}
|
|
}
|
|
return keep, reject
|
|
}
|