You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
388 B
19 lines
388 B
package misc |
|
|
|
// Ternary is a 1 line if/else statement. |
|
func Ternary[T any](condition bool, ifOutput T, elseOutput T) T { |
|
if condition { |
|
return ifOutput |
|
} |
|
|
|
return elseOutput |
|
} |
|
|
|
// TernaryF is a 1 line if/else statement whose options are functions |
|
func TernaryF[T any](condition bool, ifFunc func() T, elseFunc func() T) T { |
|
if condition { |
|
return ifFunc() |
|
} |
|
|
|
return elseFunc() |
|
}
|
|
|