From f48013805ee936db79e48cfb4f7ba59bc63883f9 Mon Sep 17 00:00:00 2001 From: KiddoV Date: Thu, 16 May 2024 22:10:14 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20IsEmptyReal=20and=20IsZeroR?= =?UTF-8?q?eal=20method=20(#174)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.go | 11 +++++++++++ check_test.go | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/check.go b/check.go index 5c73f5498..ba362f4b9 100644 --- a/check.go +++ b/check.go @@ -26,6 +26,17 @@ func IsEmpty(v any) bool { return reflects.IsEmpty(reflect.ValueOf(v)) } +// Alias of the IsEmptyReal() +var IsZeroReal = IsEmptyReal + +// IsEmptyReal checks for empty given value and also real empty value if the passed value is a pointer +func IsEmptyReal(v any) bool { + if v == nil { + return true + } + return reflects.IsEmptyReal(reflect.ValueOf(v)) +} + // IsFunc value func IsFunc(val any) bool { if val == nil { diff --git a/check_test.go b/check_test.go index 4da492e9f..5fbaed299 100644 --- a/check_test.go +++ b/check_test.go @@ -13,6 +13,10 @@ func TestIsEmpty(t *testing.T) { is.True(goutil.IsEmpty(nil)) is.False(goutil.IsZero("abc")) is.False(goutil.IsEmpty("abc")) + + is.True(goutil.IsEmptyReal(nil)) + is.False(goutil.IsZeroReal("abc")) + is.False(goutil.IsEmptyReal("abc")) } func TestIsFunc(t *testing.T) {