Findfirst on sorted array

question

#1

I have a sorted array of numbers:

A = [1, 4, 10, 15, 18]

I want to determine the first index where a value, v, occurs in this array (or 0 if it does not occur), like findfirst(A, v). But I want to exploit the fact that A is already sorted (binary search). Is this already implemented in Julia? I did not find anything on the docs for findfirst.


#2

Try searchsortedfirst.

Also, please learn how to use the help system (apropos("sorted") would have worked), and make a minimal effort to find answers before posting.


#3

Pointing out apropos("sorted") seems useful, but the rest of the answer seems unnecessarily hostile to me. It’s pretty important for growing languages to be welcoming to newcomers.


#4

Woo never noticed the apropos function :smile: , for sure you are welcome @bramtayl .


#5

This is very important though I don’t think this is a case where this rule is violated.
Reading doc string, simple search of doc and google should definitely be done, but it’s pretty hard to put together the correct search terms for either google or our doc to return the right result in this case. Combinations of sorted, find, first does not return the right function for each.

We could raise the requirement to include apropos though a much more user friendly interface must be provided for that. (Preferably an online or interactive interface, I don’t think people will try to type keywords into the REPL help mode especially when multiple keyword doesn’t work there)


#6

In Matlab (and I think also Python) each docstring includes a "See also… " section. In Matlab, the “See also” function names are clickable links to more docstrings. I find that I am rarely more than a couple of “see also” clicks away from the function I’m looking for. It’s pretty useful.

Despite having heard about it a dozen times at least, I always forget about the apropos function, or its name.


#7

There are also “See also”-s in Julia documentation (clickable to what is referred). Still not too many but it is increasing steadily. Help with this is appreciated.


#8

I also tend to forget apropos. What is the rationale for the name apropos? If I understood this maybe it would stick.


#9

Perhaps useful links:


http://www.dictionary.com/browse/apropos


#10

One of the best things about Python is that every possible dumb question has been asked on Stack Overflow, so google gives the right answer straight-away, on top of two exact-match SO posts. Julia is significantly worse in my experience.


#11

This was not my intention — if my tone came across as hostile, I apologize.

The names for this family of functions could be better organized, see