package main

import "fmt"

// section: function
func Keys(m map[any]any) []any {
	keys := make([]any, 0, len(m))
	for k := range m {
		keys = append(keys, k)
	}
	return keys
}

// section: function

func main() {
	// section: usage
	// This is cumbersome - we lose type safety
	stringIntMap := map[string]int{"a": 1, "b": 2}

	// We need to convert to map[any]any
	anyMap := make(map[any]any)
	for k, v := range stringIntMap {
		anyMap[k] = v
	}

	keys := Keys(anyMap)
	fmt.Println("Keys:", keys)

	// We need to assert types when using the results
	for _, key := range keys {
		if strKey, ok := key.(string); ok {
			fmt.Println("String key:", strKey)
		}
	}
	// section: usage
}
