mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 18:07:51 +08:00
3c5f34a217
This is so that structmaps can override the implementation of specific operations.
41 lines
816 B
Go
41 lines
816 B
Go
package vals
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// Kinder wraps the Kind method.
|
|
type Kinder interface {
|
|
Kind() string
|
|
}
|
|
|
|
// Kind returns the "kind" of the value, a concept similar to type but not yet
|
|
// very well defined. It is implemented for the builtin nil, bool and string,
|
|
// the File, List, Map types, StructMap types, and types satisfying the Kinder
|
|
// interface. For other types, it returns the Go type name of the argument
|
|
// preceded by "!!".
|
|
func Kind(v interface{}) string {
|
|
switch v := v.(type) {
|
|
case nil:
|
|
return "nil"
|
|
case bool:
|
|
return "bool"
|
|
case string:
|
|
return "string"
|
|
case float64:
|
|
return "number"
|
|
case Kinder:
|
|
return v.Kind()
|
|
case File:
|
|
return "file"
|
|
case List:
|
|
return "list"
|
|
case Map:
|
|
return "map"
|
|
case StructMap:
|
|
return "structmap"
|
|
default:
|
|
return fmt.Sprintf("!!%T", v)
|
|
}
|
|
}
|