-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
Currently there are three families of search & find functions:
- find findn findin findnz findmin findmax findfirst findlast findprev findnext
- [r]search [r]searchindex searchsorted searchsortedlast searchsortedfirst
- indexin
In the find family, find, findn return indexes of non-zero or true values. findfirst, findlast, findprev and findnext are very similar to find, but kind of iterative, and they additionally allow looking for an element in a collection (the latter behavior being similar to findin). The findmin and findmax functions are different, as they return the value and index of the min/max. Finally, findnz is even more different as it only works on matrices and returns a tuple of vectors (I,J,V) for the row- and column-index and value.
In the search family, [r]search and [r]searchindex look for strings/chars/regex in a string (though they also support bytes), the former returning a range, the latter the first index. searchsorted, searchsortedlast and searchsortedfirst look for values equal to or lower than an argument, and return a range for the first, and index for the two others.
indexin is the same as findin (i.e. returns index of elements in a collection), but it returns 0 for elements that were not found, instead of a shorter vector.
I hope that summary is exact. Please correct me if not.
Questions/ideas:
- Couldn't
findinbe renamed tofind, as the signatures do not conflict? That would meanfindfirst,findlast,findprevandfindnextwould just be iterating versions offind. Currentlyfindoffers less methods than the others.
That way,indexincould be renamed tofindinto reunite the family (or add an argument to switch behaviors?) - What justifies the difference in vocabulary between
findandsearch? I suggest we rename allsearchfunctions tofind*:searchsorted*would becomefindsorted*,searchindexwould be merged withfindfirst,rsearchindexwithfindlast.
searchcould be renamed tofindfirstrange, andrsearchtofindlastrange, making them find any sequence of values in any collection, and not only in strings; if not, nicer names could befindstrandfindrstr.
That way, you can easily get a list of interesting functions by typingfind[tab][tab]. - Maybe the series
findfirst,findlast,findprevandfindnextcould be replaced/supplemented with an iteratoreachfind/findeach?