Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move filters to new file and implement public API
- Loading branch information
Showing
2 changed files
with
49 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters