-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfilters.go
40 lines (35 loc) · 833 Bytes
/
filters.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package turtle
import "strings"
// filter a given slice of Emoji by f
func filter(emojis []*Emoji, f func(e *Emoji) bool) []*Emoji {
var r []*Emoji
for _, e := range emojis {
if f(e) {
r = append(r, e)
}
}
return r
}
// category filters a slice of Emoji by Category
func category(emojis []*Emoji, c string) []*Emoji {
return filter(emojis, func(e *Emoji) bool {
return e.Category == c
})
}
// keyword filters a slice of Emoji by Keywords
func keyword(emojis []*Emoji, k string) []*Emoji {
return filter(emojis, func(e *Emoji) bool {
for _, keyword := range e.Keywords {
if keyword == k {
return true
}
}
return false
})
}
// search Emoji in a slice by Name
func search(emojis []*Emoji, s string) []*Emoji {
return filter(emojis, func(e *Emoji) bool {
return strings.Contains(e.Name, s)
})
}