mirror of
https://github.com/tailscale/tailscale.git
synced 2025-11-01 06:04:22 +00:00
types/bool: add Int (#14984)
Add Int which converts a bool into an integer. Updates tailscale/corp#22024 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// Package bools contains the [Compare] and [Select] functions.
|
||||
// Package bools contains the [Int], [Compare], and [Select] functions.
|
||||
package bools
|
||||
|
||||
// Int returns 1 for true and 0 for false.
|
||||
func Int(v bool) int {
|
||||
if v {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// Compare compares two boolean values as if false is ordered before true.
|
||||
func Compare[T ~bool](x, y T) int {
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user