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

Can add XXXWithDefault(v, defaultValue XXX) XXX #6

Open
mei-rune opened this issue Oct 3, 2022 · 1 comment
Open

Can add XXXWithDefault(v, defaultValue XXX) XXX #6

mei-rune opened this issue Oct 3, 2022 · 1 comment

Comments

@mei-rune
Copy link

mei-rune commented Oct 3, 2022

Can add XXXWithDefault(v, defaultValue XXX) XXX

func XXXWithDefault(v, defaultValue XXX) XXX {
a, err := XXX(v)
if err == nil {
return a
}
return defaultValue
}

@cstockton
Copy link
Owner

I would be open to adding a function similar to Infer but with support for default values. I don't think I would want to increase the API to support typed variants of everything. In fact with generics released this library would look very different if I was to write it again today.

Some possible API's I may consider pull request for:

// All in one function that behaves like Infer but adds a default value.
func F(dst, v, defaultValue interface{})

// Where F can be one of the below, or some other name that makes sense:
InferWithDefault
InferDefault
InferWith
WithDefault
Default

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

No branches or pull requests

2 participants