Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- type ternary struct {
- conditionIsTrue bool
- trueValue interface{}
- }
- func If(condition bool) *ternary {
- return &ternary{conditionIsTrue: condition}
- }
- func (t *ternary) Then(trueValue interface{}) *ternary {
- if t.conditionIsTrue {
- t.trueValue = trueValue
- }
- return t
- }
- func (t *ternary) Else(falseValue interface{}) interface{} {
- if t.conditionIsTrue {
- return t.trueValue
- } else {
- return falseValue
- }
- }
- func main() {
- trueValue := If(true).Then("true value").Else("false value")
- fmt.Println("Result:", trueValue)
- falseValue := If(false).Then("true value").Else("false value")
- fmt.Println("Result:", falseValue)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement