diff options
Diffstat (limited to '')
| -rw-r--r-- | content/posts/2024-12-15-conditional-operator-go.md | 35 |
1 files changed, 35 insertions, 0 deletions
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 , а пока, +как-то так держите. + +**Не стоит** использовать в реальном коде. Я лично не вижу никакого оправдания +для использования, кроме как покекать. |
