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

[FEAT] Conversion Functions with Default Values? #111

Closed
KiddoV opened this issue Jul 18, 2023 · 2 comments
Closed

[FEAT] Conversion Functions with Default Values? #111

KiddoV opened this issue Jul 18, 2023 · 2 comments
Assignees
Labels
completed enhancement New feature or request
Milestone

Comments

@KiddoV
Copy link
Contributor

KiddoV commented Jul 18, 2023

Would be nice to have some utils to convert to a design data type, if error or not the same type then return the default vals:

I have a scenarios where I want to convert a float and want the value to be 0.0 if failed:

test := mathutil.QuietFloat(math.NaN) //=> test = NaN, I want it to always be a float type instead (0.0 if failed).

The idea...

utils.FloatOrDefault(in any, default float64)
test := utils.FloatOrDefault("test", 0.0) //=> Error, return test = 0.0

utils.StringOrDefault(in any, default string)
test := utils.StringOrDefault(nil, "hello") //=> Error, return test = "hello"

...

Something like that. you get the idea 🙂
Thanks,

@inhere inhere added the enhancement New feature or request label Jul 19, 2023
@inhere inhere added this to the v0.6.12 milestone Jul 19, 2023
inhere added a commit that referenced this issue Jul 20, 2023
…Default ... and more for convert with default

- support for issues #111
@inhere
Copy link
Member

inhere commented Jul 25, 2023

Hi @KiddoV added and released on v0.6.12

@KiddoV
Copy link
Contributor Author

KiddoV commented Jul 25, 2023

Nice. Thank you!

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

No branches or pull requests

2 participants