Deviopath › Go

Generic Max

Medium · Generics

cmp.Ordered is the constraint for types that support <. A generic function is func Max[T cmp.Ordered](a, b T) T.

Write Max that returns the larger of a and b. MaxInt and MaxString are already written so the tests can call a non-generic name.

Next: Embedded Engine