Proposal Details

In the json/v2 API proposal (#71497), it is currently proposed that we add:

// GetOption returns the value stored in opts with the provided constructor,
// reporting whether the value is present.
func GetOption[T any](opts Options, constructor func(T) Options) (T, bool)

However, I suspect most usages of GetOption only cares about the value and ignores presence.

We should simplify usage and decompose the function as:

// GetOption returns the value stored in opts with the provided constructor.
// If the value is not present, it returns the zero value.
func GetOption[T any](opts Options, constructor func(T) Options) T

// HasOption reports whether a value is present in opts with the provided constructor.
func HasOption[T any](opts Options, constructor func(T) Options) bool

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)