MCPcopy Create free account
hub / github.com/adam-hanna/arrayOperations / Filter

Function Filter

arrayOperations.go:56–66  ·  view source on GitHub ↗

Filter iterates through an array applying the guard function to each element and returns the elements that pass arr := []int{0,1,2,3,4} func isEven(i int) bool { return i % 2 == 0 } fmt.Println(Filter[int](arr, isEven)) // output: [0,2,4]

(arr []T, guard func(T) bool)

Source from the content-addressed store, hash-verified

54// fmt.Println(Filter[int](arr, isEven))
55// // output: [0,2,4]
56func Filter[T any](arr []T, guard func(T) bool) []T {
57 var ret []T
58
59 for idx := range arr {
60 if guard(arr[idx]) {
61 ret = append(ret, arr[idx])
62 }
63 }
64
65 return ret
66}
67
68// Map iterates through an array applying the transform function to each element and returns the modified array
69//

Callers 1

TestFilterFunction · 0.85

Calls 1

guardFunction · 0.85

Tested by 1

TestFilterFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…