mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
ecc8035f73
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>
18 lines
385 B
Go
18 lines
385 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package bools contains the bools.Compare function.
|
|
package bools
|
|
|
|
// Compare compares two boolean values as if false is ordered before true.
|
|
func Compare[T ~bool](x, y T) int {
|
|
switch {
|
|
case x == false && y == true:
|
|
return -1
|
|
case x == true && y == false:
|
|
return +1
|
|
default:
|
|
return 0
|
|
}
|
|
}
|