go-conv
go-conv copied to clipboard
Can add XXXWithDefault(v, defaultValue XXX) XXX
Can add XXXWithDefault(v, defaultValue XXX) XXX
func XXXWithDefault(v, defaultValue XXX) XXX { a, err := XXX(v) if err == nil { return a } return defaultValue }
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