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

     1  package vals
     2  
     3  // Dissocer wraps the Dissoc method.
     4  type Dissocer interface {
     5  	// Dissoc returns a slightly modified version of the receiver with key k
     6  	// dissociated with any value.
     7  	Dissoc(k interface{}) interface{}
     8  }
     9  
    10  // Dissoc takes a container and a key, and returns a modified version of the
    11  // container, with the given key dissociated with any value. It is implemented
    12  // for types satisfying the mapDissocable or Dissocer interface. For other
    13  // types, it returns nil.
    14  func Dissoc(a, k interface{}) interface{} {
    15  	switch a := a.(type) {
    16  	case Dissocer:
    17  		return a.Dissoc(k)
    18  	case mapDissocable:
    19  		return a.Dissoc(k)
    20  	default:
    21  		return nil
    22  	}
    23  }