Go 1.21 brings the two built-in functions min
and max
to compute the smallest or largest value of a fixed number
of arguments of ordered types.
Only a fixed number of arguments is supported. Go needs to know the number of arguments at compile time.
For string arguments the result for min
is the first argument with the
smallest (or for max
, largest) value, compared lexically byte-wise.
These new built-ins will not break your existing code that already
uses the names min and max. Built-ins aren’t keywords,
so min
and max
can be shadowed however you like.