package main

import (
	"fmt"
	"slices"
)

func main() {
	// section: example
	// Binary search requires a sorted slice
	numbers := []int{1, 3, 5, 7, 9, 11, 13, 15}

	// Search for existing value
	index, found := slices.BinarySearch(numbers, 7)
	fmt.Printf("Search for 7: index=%d, found=%v\n", index, found)

	// Search for non-existing value
	index, found = slices.BinarySearch(numbers, 8)
	fmt.Printf("Search for 8: index=%d, found=%v\n", index, found)

	// When not found, index indicates where to insert
	fmt.Printf("If we insert 8 at index %d: %v\n", index,
		slices.Insert(numbers, index, 8))
	// section: example
}
