summaryrefslogtreecommitdiffhomepage
path: root/types/bools
AgeCommit message (Collapse)AuthorFilesLines
2025-02-13types/bools: fix doc typo (#15021)Joe Tsai1-1/+1
The Select function was renamed as IfElse. Updates #cleanup Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2025-02-11types/bool: add Int (#14984)Joe Tsai2-1/+19
Add Int which converts a bool into an integer. Updates tailscale/corp#22024 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2024-12-11types/bools: add IfElse (#14272)Joe Tsai3-17/+37
The IfElse function is equivalent to the ternary (c ? a : b) operator in many other languages like C. Unfortunately, this function cannot perform short-circuit evaluation like in many other languages, but this is a restriction that's not much different than the pre-existing cmp.Or function. The argument against ternary operators in Go is that nested ternary operators become unreadable (e.g., (c1 ? (c2 ? a : b) : (c2 ? x : y))). But a single layer of ternary expressions can sometimes make code much more readable. Having the bools.IfElse function gives code authors the ability to decide whether use of this is more readable or not. Obviously, code authors will need to be judicious about their use of this helper function. Readability is more of an art than a science. Updates #cleanup Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2024-10-11types/bools: add Compare to compare boolean values (#13792)Joe Tsai2-0/+38
The bools.Compare function compares boolean values by reporting -1, 0, +1 for ordering so that it can be easily used with slices.SortFunc. Updates #cleanup Updates tailscale/corp#11038 Signed-off-by: Joe Tsai <joetsai@digital-static.net>