package main

import (
	"fmt"

	"golang.org/x/exp/constraints"
)

// section: function
func Sort[T constraints.Ordered](slice []T) []T {
	// Simple bubble sort for demonstration
	result := make([]T, len(slice))
	copy(result, slice)

	for i := 0; i < len(result); i++ {
		for j := 0; j < len(result)-1-i; j++ {
			if result[j] > result[j+1] {
				result[j], result[j+1] = result[j+1], result[j]
			}
		}
	}
	return result
}

func Min[T constraints.Ordered](a, b T) T {
	if a < b {
		return a
	}
	return b
}

// section: function

func main() {
	// section: usage
	ints := []int{3, 1, 4, 1, 5, 9, 2, 6}
	strings := []string{"banana", "apple", "cherry", "date"}
	floats := []float64{3.14, 2.71, 1.41, 1.73}

	fmt.Println("Original ints:", ints)
	fmt.Println("Sorted ints:", Sort(ints))

	fmt.Println("Original strings:", strings)
	fmt.Println("Sorted strings:", Sort(strings))

	fmt.Println("Original floats:", floats)
	fmt.Println("Sorted floats:", Sort(floats))

	fmt.Println("Min of 10 and 5:", Min(10, 5))
	fmt.Println("Min of 'apple' and 'banana':", Min("apple", "banana"))
	// section: usage
}
