lntypes+routing: add generic Min/Max functions

This commit is contained in:
bitromortac committed 2022-12-12 13:22:28 +01:00
1 parent e96d48e3a8
commit 99273cc5e1
3 files changed
+56 -6

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
package lntypes
import "golang.org/x/exp/constraints"
// Number defines a type constraint for numbers.
type Number interface {
constraints.Integer | constraints.Float
}
// Max returns the greater of the two inputs.
func Max[N Number](op1 N, op2 N) N {
if op1 > op2 {
return op1
}
return op2
}
// Min returns the lesser of the two inputs.
func Min[N Number](op1 N, op2 N) N {
if op1 < op2 {
return op1
}
return op2
}