Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IsNil function for checking nil values in Go #399

Merged
merged 1 commit into from
Dec 2, 2023

Conversation

K4L1Ma
Copy link
Contributor

@K4L1Ma K4L1Ma commented Nov 24, 2023

Description

This pull request introduces the IsNil function, which checks if a value is nil or if it's a reference type with a nil underlying value. The IsNil function is useful in cases where a simple equality check (x == nil) might not be sufficient to determine the nilness of a value.

Context

In Go, the behaviour of x == nil can vary based on the type of x. A more nuanced check is required to identify whether the underlying value is ' nil ' for reference types such as pointers, slices, maps, channels, functions, and interfaces. The reflect package provides the IsNil method, employed in this IsNil function to handle such cases.

Pre-Go 1.20 interfaces can't use [T comparable] so I did the check using the regular approach without Generics, I think in this case doesn't make much difference to have it using Generic the end goal is the same, receiving something and checking if that something is IsNil, without the need to push go version to v1.20

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8f90a52) 99.31% compared to head (34da3c6) 99.31%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #399   +/-   ##
=======================================
  Coverage   99.31%   99.31%           
=======================================
  Files          15       15           
  Lines        2037     2040    +3     
=======================================
+ Hits         2023     2026    +3     
  Misses         13       13           
  Partials        1        1           
Flag Coverage Δ
unittests 99.31% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@samber samber merged commit 2bbb3ea into samber:master Dec 2, 2023
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants