summaryrefslogtreecommitdiff
path: root/content/posts/2024-12-15-conditional-operator-go/index.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/posts/2024-12-15-conditional-operator-go/index.md')
-rw-r--r--content/posts/2024-12-15-conditional-operator-go/index.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/content/posts/2024-12-15-conditional-operator-go/index.md b/content/posts/2024-12-15-conditional-operator-go/index.md
new file mode 100644
index 0000000..edbd1ef
--- /dev/null
+++ b/content/posts/2024-12-15-conditional-operator-go/index.md
@@ -0,0 +1,35 @@
+---
+categories:
+ - Без рубрики
+date: "2024-12-15T23:47:08+03:00"
+description: ""
+image: conditional-operator-go_ternary.webp
+location: Казань
+tags:
+ - IT
+ - Go
+title: Тернарник в Go
+---
+
+Хотите немного ~~наркомании~~ сахара для Go?
+
+Их есть у меня:
+
+Тернарный оператор для Go на генериках
+
+```go
+func If[T any](condition bool, thn T, els T) T {
+ if condition {
+ return thn
+ }
+ return els
+}
+```
+
+[Плейграунд чтобы потыкать](https://go.dev/play/p/sBDnPGHce8I)
+
+Будет настроение — добавлю в свою либку https://neonxp.ru/go/extra , а пока,
+как-то так держите.
+
+**Не стоит** использовать в реальном коде. Я лично не вижу никакого оправдания
+для использования, кроме как покекать.