github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/eval/vals/kind.go (about) 1 package vals 2 3 import ( 4 "fmt" 5 "math/big" 6 ) 7 8 // Kinder wraps the Kind method. 9 type Kinder interface { 10 Kind() string 11 } 12 13 // Kind returns the "kind" of the value, a concept similar to type but not yet 14 // very well defined. It is implemented for the builtin nil, bool and string, 15 // the File, List, Map types, StructMap types, and types satisfying the Kinder 16 // interface. For other types, it returns the Go type name of the argument 17 // preceded by "!!". 18 // 19 // TODO: Decide what `kind-of` should report for an external command object 20 // and document the rationale for the choice in the doc string for `func 21 // (ExternalCmd) Kind()` as well as user facing documentation. It's not 22 // obvious why this returns "fn" rather than "external" for that case. 23 func Kind(v interface{}) string { 24 switch v := v.(type) { 25 case nil: 26 return "nil" 27 case bool: 28 return "bool" 29 case string: 30 return "string" 31 case int, *big.Int, *big.Rat, float64: 32 return "number" 33 case Kinder: 34 return v.Kind() 35 case File: 36 return "file" 37 case List: 38 return "list" 39 case Map: 40 return "map" 41 case StructMap: 42 return "structmap" 43 default: 44 return fmt.Sprintf("!!%T", v) 45 } 46 }