reflections
reflections copied to clipboard
Add `MustGet...` functions that return value directly
Hi, thanks for making this awesome library. Currently, all the Get...
functions return a tuple (value, err)
like the examples the docs show:
value, err := reflections.GetField(s, fieldName)
Can we please add equivalent MustGet...
functions that return only value
, and otherwise panic if there is an error? This would be very useful in situations like tests, where I know that the reflect must pass for the assertion to pass, so there is no need to check the error separately. This would make it easy to cut the unit test size in half since I wouldn't need double the code to write a single assert.
Example:
assert.Equal(t, "test", reflections.MustGetField(s, fieldName))
(I can raise a PR for this if it that works for you)