Skip to content

Repository files navigation

AtomicGo



AtomicGo | constraints

DownloadsLatest ReleaseTestsCoverageUnit test countLicense: MITGo report


Documentation | Contributing | Code of Conduct


go get atomicgo.dev/constraints

constraints

import"atomicgo.dev/constraints"

Package constraints provides constraints for type parameters aka. generics in Go.

This is a more comprehensive drop-in replacement for golang.org/x/exp/constraints.

Index

type Addable

Addable is a constraint that matches any type that can be added with the + operator.

typeAddableinterface {
Number|~string
}

Comparable is a constraint that matches any type that can be compared with the == and != operators.

typeComparableinterface {
comparable
}

type Complex

Complex is a constraint that matches any complex number type.

typeComplexinterface {
~complex64|~complex128
}

type Float

Float is a constraint that matches any floating point number type.

typeFloatinterface {
~float32|~float64
}

type Integer

Integer is a constraint that matches any integer type.

typeIntegerinterface {
Signed|Unsigned
}

type Number

Number is a constraint that matches any real number type. The Number constraint does not include Complex numbers, as those are not ordered. If you also need Complex numbers, use the Numeric constraint.

typeNumberinterface {
Float|Integer
}

type Numeric

Numeric is a constraint that matches any numeric type, including complex numbers.

typeNumericinterface {
Number|Complex
}

Orderable is a constraint that matches any type that can be ordered with the <, <=, >, and >= operators.

typeOrderableinterface {
Integer|Float|~string
}

type Ordered

Ordered is a constraint that matches any ordered type.

typeOrderedinterface {
Integer|Float|~string
}

type Signed

Signed is a constraint that matches any signed integer type.

typeSignedinterface {
~int|~int8|~int16|~int32|~int64
}

Unsigned is a constraint that matches any unsigned integer type.

typeUnsignedinterface {
~uint|~uint8|~uint16|~uint32|~uint64|~uintptr
}

Generated by gomarkdoc


AtomicGo.dev · with ❤️ by @MarvinJWendt | mjw.dev

About

🦖 Drop-in replacement for golang.org/x/exp/constraints with more predefined constraints

Topics

Resources

Code of conduct

Stars

4 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

Generated from atomicgo/template