MCPcopy Create free account
hub / github.com/davecheney/pub / Filter

Function Filter

internal/algorithms/algorithms.go:14–22  ·  view source on GitHub ↗

Filter returns a new slice containing all elements of the slice that satisfy the predicate function.

(s []T, f func(T) bool)

Source from the content-addressed store, hash-verified

12
13// Filter returns a new slice containing all elements of the slice that satisfy the predicate function.
14func Filter[T any](s []T, f func(T) bool) []T {
15 r := make([]T, 0, len(s))
16 for _, v := range s {
17 if f(v) {
18 r = append(r, v)
19 }
20 }
21 return r
22}
23
24// Equal returns true if all elements are equal.
25func Equal[T comparable](first, second T, rest ...T) bool {

Callers 4

AccountMethod · 0.92
TagsMethod · 0.92
TestFilterFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestFilterFunction · 0.68