github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/controlflow/conditional/conditional.go (about) 1 package conditional 2 3 // Function execute left if v, else right. 4 func Function(v bool, left, right func()) { 5 if v { 6 left() 7 } else { 8 right() 9 } 10 } 11 12 // String return left if v, else right. 13 func String(v bool, left, right string) string { 14 if v { 15 return left 16 } 17 return right 18 } 19 20 // String return left if v, else right. 21 func Bool(v bool, left, right bool) bool { 22 if v { 23 return left 24 } 25 return right 26 } 27 28 // Int64 return left if v, else right. 29 func Int64(v bool, left, right int64) int64 { 30 if v { 31 return left 32 } 33 return right 34 } 35 36 // Int32 return left if v, else right. 37 func Int32(v bool, left, right int32) int32 { 38 if v { 39 return left 40 } 41 return right 42 } 43 44 // Int16 return left if v, else right. 45 func Int16(v bool, left, right int16) int16 { 46 if v { 47 return left 48 } 49 return right 50 } 51 52 // Int8 return left if v, else right. 53 func Int8(v bool, left, right int8) int8 { 54 if v { 55 return left 56 } 57 return right 58 } 59 60 // Int return left if v, else right. 61 func Int(v bool, left, right int) int { 62 if v { 63 return left 64 } 65 return right 66 } 67 68 // Uint64 return left if v, else right. 69 func Uint64(v bool, left, right uint64) uint64 { 70 if v { 71 return left 72 } 73 return right 74 } 75 76 // Uint32 return left if v, else right. 77 func Uint32(v bool, left, right uint32) uint32 { 78 if v { 79 return left 80 } 81 return right 82 } 83 84 // Uint16 return left if v, else right. 85 func Uint16(v bool, left, right uint16) uint16 { 86 if v { 87 return left 88 } 89 return right 90 } 91 92 // Uint8 return left if v, else right. 93 func Uint8(v bool, left, right uint8) uint8 { 94 if v { 95 return left 96 } 97 return right 98 } 99 100 // Uint return left if v, else right. 101 func Uint(v bool, left, right uint) uint { 102 if v { 103 return left 104 } 105 return right 106 } 107 108 // Float32 return left if v, else right. 109 func Float32(v bool, left, right float32) float32 { 110 if v { 111 return left 112 } 113 return right 114 } 115 116 // Float64 return left if v, else right. 117 func Float64(v bool, left, right float64) float64 { 118 if v { 119 return left 120 } 121 return right 122 } 123 124 // Complex64 return left if v, else right. 125 func Complex64(v bool, left, right complex64) complex64 { 126 if v { 127 return left 128 } 129 return right 130 } 131 132 // Complex128 return left if v, else right. 133 func Complex128(v bool, left, right complex128) complex128 { 134 if v { 135 return left 136 } 137 return right 138 } 139 140 // Uintptr return left if v, else right. 141 func Uintptr(v bool, left, right uintptr) uintptr { 142 if v { 143 return left 144 } 145 return right 146 } 147 148 // Any return left if v, else right. 149 func Any(v bool, left, right interface{}) interface{} { 150 if v { 151 return left 152 } 153 return right 154 }