underscore/ternary.go
2024-11-21 05:19:03 +01:00

10 lines
330 B
Go

package underscore
// Ternary returns the first argument if the condition is true, otherwise the second argument.
// Ternary is a special form of the if statement. It allows you to write code that is more concise and less verbose.
func Ternary[T any](condition bool, pos, neg T) T {
if condition {
return pos
}
return neg
}