I aware there is no ternary operation in GO like other languages C/C++/JavaScript/Ruby…
But I found this code that is trying to do the same operation playground:
package main
import "fmt"
func main() {
a, b := 2, 3
c := (map[bool]int{true: a, false: a - 1})[a > b]
fmt.Println(c)
}
This code looks to be giving the required result, and equivalent to:
c = a>b ? a : a-1
but I do not understand it.
Can any one explain it to me (map[bool]int{})[condition]