Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 301
    Hey guys, look! I just ported the ternarity operator to the golangs! play.golang.org/p/ZgLwC_DHm0. So efficient! Commented Nov 14, 2013 at 14:35
  • 52
    @tomwilde your solution looks pretty interesting, but it lacks one of the main features of ternary operator - conditional evaluation. Commented Nov 14, 2013 at 18:13
  • 18
    @VladimirMatveev wrap the values in closures ;) Commented Nov 14, 2013 at 20:03
  • 106
    c := (map[bool]int{true: a, false: a - 1})[a > b] is an example of obfuscation IMHO, even if it works. Commented Feb 28, 2015 at 12:39
  • 75
    If if/else is the idiomatic approach then perhaps Golang could consider letting if/else clauses return a value: x = if a {1} else {0}. Go would be by no means the only language to work this way. A mainstream example is Scala. See: alvinalexander.com/scala/scala-ternary-operator-syntax Commented Aug 4, 2016 at 13:04