Skip to content

Instantly share code, notes, and snippets.

@wuriyanto48
Last active November 4, 2018 04:14
Show Gist options
  • Save wuriyanto48/ed88f17d4685394407e6fbef61134a97 to your computer and use it in GitHub Desktop.
Save wuriyanto48/ed88f17d4685394407e6fbef61134a97 to your computer and use it in GitHub Desktop.
Golang Function as Parameter example
package main
import (
"fmt"
"strings"
)
type fo func(key string, value string) bool
func Check(key string, data []string, op fo) []string{
var result []string
for _, v := range data {
if op(key, v){
result = append(result, v)
}
}
return result
}
type Persons []string
func main() {
persons := Persons{"Andi", "Beni", "Wuri", "Alan", "Ana"}
res := Check("an", persons, func(k, s string) bool {
return strings.Contains(strings.ToLower(s), strings.ToLower(k))
})
fmt.Println(res)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment