From 49458f5ffd5a48c465117ec27f6437683f75acc1 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Sat, 31 Jan 2026 20:38:50 +0300 Subject: initial --- .../posts/2024-12-15-conditional-operator-go.md | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 content/posts/2024-12-15-conditional-operator-go.md (limited to 'content/posts/2024-12-15-conditional-operator-go.md') diff --git a/content/posts/2024-12-15-conditional-operator-go.md b/content/posts/2024-12-15-conditional-operator-go.md new file mode 100644 index 0000000..480ba42 --- /dev/null +++ b/content/posts/2024-12-15-conditional-operator-go.md @@ -0,0 +1,35 @@ +--- +categories: +- Без рубрики +date: '2024-12-15T23:47:08+03:00' +description: '' +image: files/2024-12-15-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 , а пока, +как-то так держите. + +**Не стоит** использовать в реальном коде. Я лично не вижу никакого оправдания +для использования, кроме как покекать. -- cgit v1.2.3