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 EmptyableToPtr #311

Merged
merged 2 commits into from
Mar 20, 2023
Merged

Add EmptyableToPtr #311

merged 2 commits into from
Mar 20, 2023

Conversation

senago
Copy link
Contributor

@senago senago commented Feb 17, 2023

Closes #310

@samber
Copy link
Owner

samber commented Feb 20, 2023

Hi @senago and thanks for this first contribution.

In order to match other helper names, i would rename zero to empty.

Also, about converting a zero value to nil, to recreate a nullable type, i think you should check samber/mo and mo.EmptyableToOption

@codecov-commenter
Copy link

Codecov Report

Base: 99.28% // Head: 99.29% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (69ed2a6) compared to base (0ae2307).
Patch coverage: 100.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #311   +/-   ##
=======================================
  Coverage   99.28%   99.29%           
=======================================
  Files          15       15           
  Lines        1971     1977    +6     
=======================================
+ Hits         1957     1963    +6     
  Misses         13       13           
  Partials        1        1           
Flag Coverage Δ
unittests 99.29% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
type_manipulation.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@senago senago changed the title Add ToNonzeroPtr Add EmptyableToPtr Feb 20, 2023
@senago
Copy link
Contributor Author

senago commented Feb 20, 2023

Thank you for the review! Indeed, looks like here it's better to resort to reflect to cover more cases. Renamed the function to EmptyableToPtr for consistency with both lo and mo.

@samber samber merged commit 56f34e0 into samber:master Mar 20, 2023
@vikstrous2
Copy link

I'm really curious now what's the difference between an equality check and reflection? Is slices one of them?

@senago
Copy link
Contributor Author

senago commented Jun 12, 2023

Equality check is enabled for comparable types

// comparable is an interface that is implemented by all comparable types
// (booleans, numbers, strings, pointers, channels, arrays of comparable types,
// structs whose fields are all comparable types).

So, the point was to support other commonly used types - maps, slices of uncomparable types, errors, etc.

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.

Add function ToNonzeroPtr that handles zero values
4 participants