github.com/elves/elvish@v0.15.0/pkg/eval/vals/kind.go (about)

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