github.com/elves/elvish@v0.15.0/pkg/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 the Map type and types satisfying the Dissocer interface. For other
    13  // types, it returns nil.
    14  func Dissoc(a, k interface{}) interface{} {
    15  	switch a := a.(type) {
    16  	case Map:
    17  		return a.Dissoc(k)
    18  	case Dissocer:
    19  		return a.Dissoc(k)
    20  	default:
    21  		return nil
    22  	}
    23  }