You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
The linear search listed above is so trivial in implementation that I wouldn't think it's worth adding, binary search is far superior if you can afford the sort.
Adding this would set a precedent for many other little "useful" utility functions that are trivial to write. Where does it end? I'm against adding things like this to the std lib.
@Ganners I wasn't aware of sort.SearchStrings existence... Thanks for pointing it out. You're right, a binary search would be a better choice.
@griesemer: I wouldn't ask for a Max(ints []int) int function, but as there is already a package with string utility functions in place, I thought it would be a nice addition. I scrolled multiple times through the package to check if there is really no such function already there. ;)
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. ;)
The text was updated successfully, but these errors were encountered: