package main

import "fmt"

// section: function
func Transform[T any, U any](input T, transformer func(T) U) U {
	return transformer(input)
}

// section: function

func main() {
	// section: usage
	// Transform string to int
	result1 := Transform("hello", func(s string) int {
		return len(s)
	})
	fmt.Println("String length:", result1)

	// Transform int to string
	result2 := Transform(42, func(i int) string {
		return fmt.Sprintf("Number: %d", i)
	})
	fmt.Println("Formatted number:", result2)

	// Transform int to bool
	result3 := Transform(10, func(i int) bool {
		return i%2 == 0
	})
	fmt.Println("Is even:", result3)
	// section: usage
}
