Find by Value in Go
package main
import (
"fmt"
"strings"
)
func FindStr(list []string, pred func(s string) bool) string {
for _, s := range list {
if pred(s) {
return s
}
}
return ""
}
func main() {
list := []string{"slice", "of", "strings"}
res := FindStr(list, func(s string) bool {
return strings.HasPrefix(s, "o")
})
fmt.Println(res)
}