mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Moved everything out of internal
This commit is contained in:
34
utils/string_collections.go
Normal file
34
utils/string_collections.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package utils
|
||||
|
||||
// https://gobyexample.com/collection-functions
|
||||
|
||||
func StrIndex(vs []string, t string) int {
|
||||
for i, v := range vs {
|
||||
if v == t {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func StrInclude(vs []string, t string) bool {
|
||||
return StrIndex(vs, t) >= 0
|
||||
}
|
||||
|
||||
func StrFilter(vs []string, f func(string) bool) []string {
|
||||
vsf := make([]string, 0)
|
||||
for _, v := range vs {
|
||||
if f(v) {
|
||||
vsf = append(vsf, v)
|
||||
}
|
||||
}
|
||||
return vsf
|
||||
}
|
||||
|
||||
func StrMap(vs []string, f func(string) string) []string {
|
||||
vsm := make([]string, len(vs))
|
||||
for i, v := range vs {
|
||||
vsm[i] = f(v)
|
||||
}
|
||||
return vsm
|
||||
}
|
||||
Reference in New Issue
Block a user