github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/cmds/core/elvish/eval/vals/kind.go (about) 1 package vals 2 3 import ( 4 "fmt" 5 6 "github.com/u-root/u-root/cmds/core/elvish/hashmap" 7 "github.com/u-root/u-root/cmds/core/elvish/vector" 8 ) 9 10 // Kinder wraps the Kind method. 11 type Kinder interface { 12 Kind() string 13 } 14 15 // Kind returns the "kind" of the value, a concept similar to type but not yet 16 // very well defined. It is implemented for the builtin types bool and string, 17 // the Vector and Map types, and types implementing the Kinder interface. For 18 // other types, it returns the Go type name of the argument preceded by "!!". 19 func Kind(v interface{}) string { 20 switch v := v.(type) { 21 case Kinder: 22 return v.Kind() 23 case bool: 24 return "bool" 25 case string: 26 return "string" 27 case vector.Vector: 28 return "list" 29 case hashmap.Map: 30 return "map" 31 default: 32 return fmt.Sprintf("!!%T", v) 33 } 34 }