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
findin
be renamed tofind
, as the signatures do not conflict? That would meanfindfirst
,findlast
,findprev
andfindnext
would just be iterating versions offind
. Currentlyfind
offers less methods than the others.
That way,indexin
could be renamed tofindin
to reunite the family (or add an argument to switch behaviors?) - What justifies the difference in vocabulary between
find
andsearch
? I suggest we rename allsearch
functions tofind*
:searchsorted*
would becomefindsorted*
,searchindex
would be merged withfindfirst
,rsearchindex
withfindlast
.
search
could be renamed tofindfirstrange
, andrsearch
tofindlastrange
, making them find any sequence of values in any collection, and not only in strings; if not, nicer names could befindstr
andfindrstr
.
That way, you can easily get a list of interesting functions by typingfind[tab][tab]
. - Maybe the series
findfirst
,findlast
,findprev
andfindnext
could be replaced/supplemented with an iteratoreachfind
/findeach
?