Skip to content

Instantly share code, notes, and snippets.

@fpagyu
Created October 15, 2019 10:23
Show Gist options
  • Save fpagyu/aeb772f56b4ac0ccbe59e976f0fc8d6c to your computer and use it in GitHub Desktop.
Save fpagyu/aeb772f56b4ac0ccbe59e976f0fc8d6c to your computer and use it in GitHub Desktop.
Go三元表达式
func If(condition bool, trueVal, falseVal interface{}) interface{} {
if condition {
return trueVal
}
return falseVal
}
a, b := 2, 3
max := If(a > b, a, b).(int)
println(max)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment