MCPcopy Index your code
hub / github.com/adam-hanna/arrayOperations / FindOne

Function FindOne

arrayOperations.go:12–20  ·  view source on GitHub ↗

FindOne iterates through an array applying the guard function to each element and returns the first element that passes. If no such element is found, it returns the zero value and false. arr := []int{1,2,3,4} func isEven(i int) bool { return i % 2 == 0 } fmt.Println(FindOne[int](arr, isEven)

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

Source from the content-addressed store, hash-verified

10// fmt.Println(FindOne[int](arr, isEven))
11// // output: [2]
12func FindOne[T any](arr []T, guard func(T) bool) (T, bool) {
13 for idx := range arr {
14 if guard(arr[idx]) {
15 return arr[idx], true
16 }
17 }
18
19 return *new(T), false
20}
21
22// Reduce iterates through an array applying the function to each element and the cumulative value and the final state of the cumulative value
23//

Callers 1

TestFindOneFunction · 0.85

Calls 1

guardFunction · 0.85

Tested by 1

TestFindOneFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…