From 52b5c840f7e27ad3a2cad0ac4d883c8ee9667f37 Mon Sep 17 00:00:00 2001 From: some Date: Sun, 29 Sep 2024 13:35:40 -0400 Subject: [PATCH] Initial release --- .editorconfig | 35 +++++++++++++++++++++++++++++++++++ coalesce.go | 10 ++++++++++ defaults.go | 6 ++++++ go.mod | 3 +++ 4 files changed, 54 insertions(+) create mode 100644 .editorconfig create mode 100644 coalesce.go create mode 100644 defaults.go create mode 100644 go.mod diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0cf80d3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,35 @@ +root = true + +[*] +charset = utf-8 + +end_of_line = LF +insert_final_newline = true +trim_trailing_whitespace = true + +indent_style = space +indent_size = 2 + +[*.sh] +indent_style = space +indent_size = 4 + +[{*.html,*.js,*.css,*.scss}] +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab +indent_size = 8 + +[{{*.,}[Dd]ockerfile{.*,},{*.,}[Cc]ontainerfile{.*,}}] +indent_style = space +indent_size = 4 + +[*.proto] +indent_style = space +indent_size = 2 + +[{*.go,go.mod}] +indent_style = tab +indent_size = 8 diff --git a/coalesce.go b/coalesce.go new file mode 100644 index 0000000..b564320 --- /dev/null +++ b/coalesce.go @@ -0,0 +1,10 @@ +package defaults + +func Coalesce[T comparable](variables ...T) (result T) { + for _, v := range variables { + if !Empty(v) { + return v + } + } + return +} diff --git a/defaults.go b/defaults.go new file mode 100644 index 0000000..431ee1b --- /dev/null +++ b/defaults.go @@ -0,0 +1,6 @@ +package defaults + +func Empty[T comparable](val T) bool { + var empty T + return val == empty +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..61f0ae9 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module somehole.com/minecraft/defaults + +go 1.23.1