News for hackers. Stuff that matters.
Re:Binary Search Reconsidered (2018) by tsimionescu on Friday December 25, 2020 @03:46PM (#25538912)

  fn binary_search<T: Ord>(mut array: &[T], key: T) -> Option<T>
A more useful signature would have been

  fn binary_search<T: Ord>(mut array: &[T], key: T) -> Option<usize> 
And then returning `Some(middle)` on the Equal match. Returning the value you were given or None would be better expressed as returning True/False to avoid the unnecessary copy.
Re:Binary Search Reconsidered (2018) by justinpombrio on Friday December 25, 2020 @10:49PM (#25541231)
> A more useful signature would have been [returning the index].

Good point! And if you're doing that, there's no reason to use slices. So I guess the only thing to learn from my code... is that slices do useful bookkeeping for problems similar to this, in the case that you don't care about the indices?

> Returning the value you were given or None would be better expressed as returning True/False to avoid the unnecessary copy.

Just because two values are equal, doesn't mean they're the same. Though my function signature was wonky, regardless.