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

feature: Add functions safeDefault, safeCoalesce, and nonNil #385

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

govindbalaji-s
Copy link

@govindbalaji-s govindbalaji-s commented Oct 21, 2023

Fixes #250

This adds functions similar to default and coalesce but only falls through for nil values, and does not fall through 0, false or "".

Suggestions for better names are welcome. Have picked same names as in #250 .

IMO safeEmpty should just be ne nil and is not needed.
ne actually fails when comparing nil and something else. Added a function nonNil for this.

@govindbalaji-s govindbalaji-s changed the title Add functions safeDefault and safeCoalesce feature: Add functions safeDefault and safeCoalesce Oct 21, 2023
defaults.go Show resolved Hide resolved
@govindbalaji-s govindbalaji-s changed the title feature: Add functions safeDefault and safeCoalesce feature: Add functions safeDefault, safeCoalesce, and nonNil Jan 31, 2024
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 safeEmpty, safeDefault, and safeCoalesce functions which don't consider 0 or false to be empty
2 participants