github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/cmds/core/elvish/eval/vals/bool.go (about)

     1  package vals
     2  
     3  // Booler wraps the Bool method.
     4  type Booler interface {
     5  	// Bool computes the truth value of the receiver.
     6  	Bool() bool
     7  }
     8  
     9  // Bool converts a value to bool. It is implemented for the builtin bool type
    10  // and types implementing the Booler interface. For all other values, it returns
    11  // true.
    12  func Bool(v interface{}) bool {
    13  	switch v := v.(type) {
    14  	case Booler:
    15  		return v.Bool()
    16  	case bool:
    17  		return v
    18  	}
    19  	return true
    20  }