Search Sorted Slices with slices.BinarySearch in Go
slices.BinarySearch returns more than a membership result. Its index identifies the earliest matching position when a target exists, and the position where that target belongs when it does not. That dual contract makes the function useful for maintaining sorted data as well as querying it. The standard-library signature accepts ordered element types: func BinarySearch[S ~[]E, E cmp.Ordered](x S, target E) (int, bool) The input must already be sorted in increasing order. The function does not sort, copy, or mutate the slice.