From bfdd73d7324a4f66a16f55d4fb064b0ff08d40e9 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Mon, 2 Feb 2026 00:35:54 +0300 Subject: =?UTF-8?q?=D0=91=D0=BE=D0=BB=D1=8C=D1=88=D0=B0=D1=8F=20=D1=87?= =?UTF-8?q?=D0=B8=D1=81=D1=82=D0=BA=D0=B0=20=D0=B1=D0=BB=D0=BE=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../conditional-operator-go_ternary.webp | Bin 0 -> 7408 bytes .../2024-12-15-conditional-operator-go/index.md | 35 +++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 content/posts/2024-12-15-conditional-operator-go/conditional-operator-go_ternary.webp create mode 100644 content/posts/2024-12-15-conditional-operator-go/index.md (limited to 'content/posts/2024-12-15-conditional-operator-go') diff --git a/content/posts/2024-12-15-conditional-operator-go/conditional-operator-go_ternary.webp b/content/posts/2024-12-15-conditional-operator-go/conditional-operator-go_ternary.webp new file mode 100644 index 0000000..5eeea58 Binary files /dev/null and b/content/posts/2024-12-15-conditional-operator-go/conditional-operator-go_ternary.webp differ 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 , а пока, +как-то так держите. + +**Не стоит** использовать в реальном коде. Я лично не вижу никакого оправдания +для использования, кроме как покекать. -- cgit v1.2.3