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

     1  package vals
     2  
     3  import "reflect"
     4  
     5  var (
     6  	dummy              interface{}
     7  	nilValue           = reflect.ValueOf(&dummy).Elem()
     8  	emptyInterfaceType = reflect.TypeOf(&dummy).Elem()
     9  )
    10  
    11  // ValueOf is like reflect.ValueOf, except that when given an argument of nil,
    12  // it does not return a zero Value, but the Value for the zero value of the
    13  // empty interface.
    14  func ValueOf(i interface{}) reflect.Value {
    15  	if i == nil {
    16  		return nilValue
    17  	}
    18  	return reflect.ValueOf(i)
    19  }
    20  
    21  // TypeOf is like reflect.TypeOf, except that when given an argument of nil, it
    22  // does not return nil, but the Type for the empty interface.
    23  func TypeOf(i interface{}) reflect.Type {
    24  	if i == nil {
    25  		return emptyInterfaceType
    26  	}
    27  	return reflect.TypeOf(i)
    28  }