Skip to content

Commit

Permalink
feat(reflectx): add is empty value
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Jan 15, 2025
1 parent cd00cf0 commit 7cb23db
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions reflectx/value.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package reflectx

import "reflect"

func IsEmptyValue(v reflect.Value) bool {
switch v.Kind() {

Check failure on line 6 in reflectx/value.go

View workflow job for this annotation

GitHub Actions / lint

missing cases in switch of type reflect.Kind: reflect.Invalid, reflect.Complex64, reflect.Complex128, reflect.Chan, reflect.Func, reflect.Struct, reflect.UnsafePointer (exhaustive)
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
return v.Len() == 0
case reflect.Bool,
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
reflect.Float32, reflect.Float64,
reflect.Interface, reflect.Pointer:
return v.IsZero()
}
return false
}

0 comments on commit 7cb23db

Please sign in to comment.