cmpx

package
v1.54.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2023 License: BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package cmpx has code that will likely land in a future version of Go, but we want sooner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare added in v1.48.0

func Compare[T Ordered](x, y T) int

Compare returns

-1 if x is less than y,
 0 if x equals y,
+1 if x is greater than y.

For floating-point types, a NaN is considered less than any non-NaN, a NaN is considered equal to a NaN, and -0.0 is equal to 0.0.

func Or

func Or[T comparable](list ...T) T

Or returns the first non-zero element of list, or else returns the zero T.

This is the proposal from https://github.com/golang/go/issues/60204#issuecomment-1581245334.

Types

type Ordered added in v1.48.0

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64 |
		~string
}

Ordered is cmp.Ordered from Go 1.21.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL