github.com/andeya/ameda@v1.5.3/bool.go (about) 1 package ameda 2 3 import ( 4 "strconv" 5 ) 6 7 // BoolToInterface converts bool to interface. 8 func BoolToInterface(v bool) interface{} { 9 return v 10 } 11 12 // BoolToInterfacePtr converts bool to *interface. 13 func BoolToInterfacePtr(v bool) *interface{} { 14 r := BoolToInterface(v) 15 return &r 16 } 17 18 // BoolToString converts bool to string. 19 func BoolToString(v bool) string { 20 return strconv.FormatBool(v) 21 } 22 23 // BoolToStringPtr converts bool to *string. 24 func BoolToStringPtr(v bool) *string { 25 r := BoolToString(v) 26 return &r 27 } 28 29 // BoolToBoolPtr converts bool to *bool. 30 func BoolToBoolPtr(v bool) *bool { 31 return &v 32 } 33 34 // BoolToFloat32 converts bool to float32. 35 func BoolToFloat32(v bool) float32 { 36 if v { 37 return 1 38 } 39 return 0 40 } 41 42 // BoolToFloat32Ptr converts bool to *float32. 43 func BoolToFloat32Ptr(v bool) *float32 { 44 r := BoolToFloat32(v) 45 return &r 46 } 47 48 // BoolToFloat64 converts bool to float64. 49 func BoolToFloat64(v bool) float64 { 50 if v { 51 return 1 52 } 53 return 0 54 } 55 56 // BoolToFloat64Ptr converts bool to *float64. 57 func BoolToFloat64Ptr(v bool) *float64 { 58 r := BoolToFloat64(v) 59 return &r 60 } 61 62 // BoolToInt converts bool to int. 63 func BoolToInt(v bool) int { 64 if v { 65 return 1 66 } 67 return 0 68 } 69 70 // BoolToIntPtr converts bool to *int. 71 func BoolToIntPtr(v bool) *int { 72 r := BoolToInt(v) 73 return &r 74 } 75 76 // BoolToInt8 converts bool to int8. 77 func BoolToInt8(v bool) int8 { 78 if v { 79 return 1 80 } 81 return 0 82 } 83 84 // BoolToInt8Ptr converts bool to *int8. 85 func BoolToInt8Ptr(v bool) *int8 { 86 r := BoolToInt8(v) 87 return &r 88 } 89 90 // BoolToInt16 converts bool to int16. 91 func BoolToInt16(v bool) int16 { 92 if v { 93 return 1 94 } 95 return 0 96 } 97 98 // BoolToInt16Ptr converts bool to *int16. 99 func BoolToInt16Ptr(v bool) *int16 { 100 r := BoolToInt16(v) 101 return &r 102 } 103 104 // BoolToInt32 converts bool to int32. 105 func BoolToInt32(v bool) int32 { 106 if v { 107 return 1 108 } 109 return 0 110 } 111 112 // BoolToInt32Ptr converts bool to *int32. 113 func BoolToInt32Ptr(v bool) *int32 { 114 r := BoolToInt32(v) 115 return &r 116 } 117 118 // BoolToInt64 converts bool to int64. 119 func BoolToInt64(v bool) int64 { 120 if v { 121 return 1 122 } 123 return 0 124 } 125 126 // BoolToInt64Ptr converts bool to *int64. 127 func BoolToInt64Ptr(v bool) *int64 { 128 r := BoolToInt64(v) 129 return &r 130 } 131 132 // BoolToUint converts bool to uint. 133 func BoolToUint(v bool) uint { 134 if v { 135 return 1 136 } 137 return 0 138 } 139 140 // BoolToUintPtr converts bool to *uint. 141 func BoolToUintPtr(v bool) *uint { 142 r := BoolToUint(v) 143 return &r 144 } 145 146 // BoolToUint8 converts bool to uint8. 147 func BoolToUint8(v bool) uint8 { 148 if v { 149 return 1 150 } 151 return 0 152 } 153 154 // BoolToUint8Ptr converts bool to *uint8. 155 func BoolToUint8Ptr(v bool) *uint8 { 156 r := BoolToUint8(v) 157 return &r 158 } 159 160 // BoolToUint16 converts bool to uint16. 161 func BoolToUint16(v bool) uint16 { 162 if v { 163 return 1 164 } 165 return 0 166 } 167 168 // BoolToUint16Ptr converts bool to *uint16. 169 func BoolToUint16Ptr(v bool) *uint16 { 170 r := BoolToUint16(v) 171 return &r 172 } 173 174 // BoolToUint32 converts bool to uint32. 175 func BoolToUint32(v bool) uint32 { 176 if v { 177 return 1 178 } 179 return 0 180 } 181 182 // BoolToUint32Ptr converts bool to *uint32. 183 func BoolToUint32Ptr(v bool) *uint32 { 184 r := BoolToUint32(v) 185 return &r 186 } 187 188 // BoolToUint64 converts bool to uint64. 189 func BoolToUint64(v bool) uint64 { 190 if v { 191 return 1 192 } 193 return 0 194 } 195 196 // BoolToUint64Ptr converts bool to *uint64. 197 func BoolToUint64Ptr(v bool) *uint64 { 198 r := BoolToUint64(v) 199 return &r 200 }