github.com/tobgu/qframe@v0.4.0/function/bool.go (about) 1 package function 2 3 import "strconv" 4 5 // NotB returns the inverse of x 6 func NotB(x bool) bool { 7 return !x 8 } 9 10 // AndB returns the logical conjunction of x and y. 11 func AndB(x, y bool) bool { 12 return x && y 13 } 14 15 // OrB returns the logical disjunction of x and y. 16 func OrB(x, y bool) bool { 17 return x || y 18 } 19 20 // XorB returns the exclusive disjunction of x and y 21 func XorB(x, y bool) bool { 22 return (x && !y) || (!x && y) 23 } 24 25 // NandB returns the inverse logical conjunction of x and b. 26 func NandB(x, y bool) bool { 27 return !AndB(x, y) 28 } 29 30 // StrB returns the string representation of x. 31 func StrB(x bool) *string { 32 result := strconv.FormatBool(x) 33 return &result 34 } 35 36 // IntB casts x to int. true => 1 and false => 0. 37 func IntB(x bool) int { 38 if x { 39 return 1 40 } 41 42 return 0 43 }