MCPcopy Index your code
hub / github.com/expr-lang/expr / isEmpty

Function isEmpty

internal/testify/assert/assertions.go:716–742  ·  view source on GitHub ↗

isEmpty gets whether the specified object is considered empty or not.

(object interface{})

Source from the content-addressed store, hash-verified

714
715// isEmpty gets whether the specified object is considered empty or not.
716func isEmpty(object interface{}) bool {
717
718 // get nil case out of the way
719 if object == nil {
720 return true
721 }
722
723 objValue := reflect.ValueOf(object)
724
725 switch objValue.Kind() {
726 // collection types are empty when they have no element
727 case reflect.Chan, reflect.Map, reflect.Slice:
728 return objValue.Len() == 0
729 // pointers are empty if nil or if the value they point to is empty
730 case reflect.Ptr:
731 if objValue.IsNil() {
732 return true
733 }
734 deref := objValue.Elem().Interface()
735 return isEmpty(deref)
736 // for all other types, compare against the zero value
737 // array types are empty when they match their zero-initialized state
738 default:
739 zero := reflect.Zero(objValue.Type())
740 return reflect.DeepEqual(object, zero.Interface())
741 }
742}
743
744// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
745// a slice or a channel with len == 0.

Callers 4

Test_isEmptyFunction · 0.85
EmptyFunction · 0.85
NotEmptyFunction · 0.85
ElementsMatchFunction · 0.85

Calls 4

ElemMethod · 0.80
TypeMethod · 0.65
LenMethod · 0.45
ZeroMethod · 0.45

Tested by 1

Test_isEmptyFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…