Source File
ordered.go
Belonging Package
go101.org/nstd
package nstd
// Ordered is a constraint that permits any ordered type: any type
// that supports the operators < <= >= >.
// If future releases of Go add new ordered types,
// this constraint will be modified to include them.
type Ordered interface {
Real | ~string
}
func minOfTwo[ Ordered](, ) {
if < {
return
}
return
}
// Clamp clamps an ordered value within a range.
// Both min and max are inclusive.
// If v is NaN, then NaN is returned.
//
// See: https://github.com/golang/go/issues/58146
func [ Ordered](, , ) {
if > {
Panicf("min (%v) > max (%v)!", , )
}
if < {
return
}
if > {
return
}
return
}
The pages are generated with Golds v0.7.0-preview. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |