While reading the source code of many packages lately I stumbled a lot over the following function declaration:
func stringInList(list []string, str string) bool {
for _, val := range list {
if val == str {
return true
}
}
return false
}
I have the feeling that searching a slice of strings for the first occurrence of a string is a very common need and might be a good addition to the standard library.
I would propose the following function for the strings package:
func ListIndex(list []string, str string) int {
for i, val := range list {
if val == str {
return i
}
}
return -1
}
I know adding stuff to the standard library is a big thing, but I had to give it a least a try. ;)
While reading the source code of many packages lately I stumbled a lot over the following function declaration:
I have the feeling that searching a slice of strings for the first occurrence of a string is a very common need and might be a good addition to the standard library.
I would propose the following function for the strings package:
I know adding stuff to the standard library is a big thing, but I had to give it a least a try. ;)