I've long wanted to add a binary search to
Range because of how useful binary search can be even without a slice, how could this best be approached?
It doesn't seem possible to use the
Step trait in its current form for this, so I see a couple options:
Range<usize>(since that's by far the most important one)
What do you mean by binary search on range? What would you be searching in?
You'd be searching in the range itself. I should have been more specific, this only works with
binary_search as it's currently on
[T] would indeed make no sense
The signature of
Range<usize>::binary_search_by would be
fn binary_search_by<F: FnMut(usize) -> Ordering>(&self, f: F) -> Result<usize, usize>
and using that
[T]::binary_search_by could be reimplemented using something like
is it something like Go's
It does seem like it! The main difference being that by having the closure return an
Ordering, the function is able to return
Err depending on whether the search "succeeded"