Documentation
¶
Index ¶
- func IsEqual(cmp int) bool
- func IsGreater(cmp int) bool
- func IsGreaterOrEqual(cmp int) bool
- func IsLess(cmp int) bool
- func IsLessOrEqual(cmp int) bool
- func IsMore(cmp int) bool
- func IsMoreOrEqual(cmp int) bool
- func Numbers[T constraints.Number](a, b T) int
- func Strings[S ~string](a, b S) int
- type Interface
- type ShortInterface
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsGreaterOrEqual ¶
IsGreaterOrEqual reports whether the receiver is greater than or equal to another value.
func IsLessOrEqual ¶
IsLessOrEqual reports whether the receiver is less than or equal to another value.
func IsMoreOrEqual ¶
IsMoreOrEqual reports whether the receiver is more than or equal to another value.
func Numbers ¶
func Numbers[T constraints.Number](a, b T) int
func Strings ¶ added in v0.304.0
Example ¶
package main
import (
"go.llib.dev/frameless/pkg/compare"
)
func main() {
compare.Strings("a", "b")
compare.Strings("a", "a")
compare.Strings("b", "a")
}
Example (CustomStringType) ¶
package main
import (
"go.llib.dev/frameless/pkg/compare"
)
func main() {
type STR string
var a, b STR = "a", "b"
compare.Strings(a, b)
}
Types ¶
type Interface ¶
type Interface[T any] interface { // Compare returns: // -1 if receiver is less than the argument, // 0 if they're equal, and // +1 if receiver is greater. // // Think of the result of Compare like a seesaw: // The side that’s lower (touching the ground) represents the smaller value. // The side that’s up shows the larger value — it’s higher, so it’s greater. // // Implementors must ensure consistent ordering semantics. Compare(T) int }
Interface defines how comparison can be implemented. An implementation of Interface can be sorted by the routines in this package. The methods refer to elements of the underlying collection by integer index.
Types implementing this interface must provide a Compare method that defines the ordering or equivalence of values. This pattern is useful when working with: 1. Custom user-defined types requiring comparison logic 2. Encapsulated values needing semantic comparisons 3. Comparison-agnostic systems (e.g., sorting algorithms)
Example usage:
type MyNumber int
func (m MyNumber) Compare(other MyNumber) int {
if m < other {
return -1
}
if other < m {
return +1
}
return 0
}