From 6481fe2665db9a8c2f586fcf331803f891e503a7 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Sat, 5 Aug 2023 16:15:54 +0200 Subject: [PATCH] Added min function to utils to get min between two comparable types (how isn't it in the STL?) --- go.mod | 2 ++ go.sum | 2 ++ utils/utils.go | 13 ++++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 go.sum diff --git a/go.mod b/go.mod index 47380af..5033a7e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module maze-solver go 1.20 + +require golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9cf7e1c --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI= +golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= diff --git a/utils/utils.go b/utils/utils.go index 18aa4cb..717c2e2 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,6 +1,10 @@ package utils -import "log" +import ( + "log" + + "golang.org/x/exp/constraints" +) func Check(err error, msg string, args ...any) { if err != nil { @@ -8,3 +12,10 @@ func Check(err error, msg string, args ...any) { panic(err) } } + +func Min[T constraints.Ordered](a, b T) T { + if a < b { + return a + } + return b +}