Add filter.Prefix

pull/53/head v0.0.7
rwxrob 2 years ago
parent 2c74b4dd18
commit 1bb6a0b8b2
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -75,3 +75,12 @@ func Keys[T any](m map[string]T) []string {
}
return keys
}
// Prefix returns a new slice with prefix added to each string.
func Prefix(in []string, pre string) []string {
list := []string{}
for _, i := range in {
list = append(list, pre+i)
}
return list
}

@ -50,3 +50,9 @@ func ExampleKeys() {
// [one three two]
// [one three two]
}
func ExamplePrefix() {
fmt.Println(filter.Prefix([]string{"foo", "bar"}, "my"))
// Output:
// [myfoo mybar]
}

Loading…
Cancel
Save