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

Suggestion to add a method to return default value provided by user if Val is not Valid #14

Closed
apatniv opened this issue Jan 1, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@apatniv
Copy link
Contributor

apatniv commented Jan 1, 2024

Thanks for providing a useful library.

Currently, I need to do the following to determine the default value

const defaultPath = "magic.dat" // somewhere in the package

optPath := gonull.NewNullable("hello.dat")
path := ""
if optPath.Valid {
    path = optPath.Val
} else {
    path = defaultPath
}

Suggestion is to add a new receiver method OrElse so that this can be done in one line

path := optPath.OrElse(defaultPath)

Signature:

func (n *Nullable[T]) OrElse(value T) T
@apatniv
Copy link
Contributor Author

apatniv commented Jan 1, 2024

I can make the PR if you are ok. Thanks

@LukaGiorgadze LukaGiorgadze added the enhancement New feature or request label Jan 2, 2024
@LukaGiorgadze
Copy link
Owner

Hey @apatniv, this is really nice feature and I would love to see it in the next release. using OrElse we can reduce the amount of if else conditions.

Feel free to rise a PR, I'll be more than happy to approve it.

Thank you for your feedback and open-source contribution.

@LukaGiorgadze
Copy link
Owner

PR #17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants