Documentation ¶
Index ¶
- func CanCompare[E any](e1 E, e2 E) bool
- func Compare[E any](e1 E, e2 E) int
- func Equal[E any](e1 E, e2 E) bool
- func QuickSort[T any](slice []T, compareFunc func(o1, o2 T) int)
- func Sort[T any](slice []T, compareFunc ...CompareFunc[T])
- type Comparable
- type CompareFunc
- type Iterable
- type Iterator
- type JSONDeserializer
- type JSONSerializer
- type ToString
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanCompare ¶
func Compare ¶
Compare First, use comparator for comparison. If not, use Compare again. If not, use Golang's default sorting rules
func Sort ¶
func Sort[T any](slice []T, compareFunc ...CompareFunc[T])
Types ¶
type Comparable ¶
Comparable is a function type used to define a comparison interface in GoKit collection.
type CompareFunc ¶
CompareFunc is a function type used to define a comparison function in GoKit collection. It imposes a total ordering on a collection of objects. Comparators can be passed to sorting methods to provide precise control over the sort order. Comparators can also be used to control the order of certain data structures, such as sorted sets or sorted maps, or to provide an ordering for collections of objects that don't have a natural ordering.
The comparison function takes two arguments, 'o1' and 'o2', of type 'T' (a comparable type), and returns an integer value that represents the comparison result: - A negative value if 'o1' is less than 'o2'. - Zero if 'o1' is equal to 'o2'. - A positive value if 'o1' is greater than 'o2'.
Example usage: func CompareInt(a, b int) int { if a < b { return -1 } else if a > b { return 1 } return 0 }
var compareFn Compare[int] = CompareInt
Using the comparison function in a sort operation: someInts := []int{3, 1, 4, 1, 5, 9, 2, 6, 5} sort.Slice(someInts, func(i, j int) bool { return compareFn(someInts[i], someInts[j]) < 0 })
type Iterable ¶
type Iterable interface { // Iterator returns an iterator for the collection. Iterator() Iterator }
Iterable represents a collection that can be iterated over.
type Iterator ¶
type Iterator interface { // Next returns true if there are more elements to iterate, or false otherwise. Next() bool // Value returns the current value of the iterator. Value() interface{} }
Iterator represents an iterator over a collection.
type JSONDeserializer ¶ added in v0.1.2
type JSONDeserializer interface { // FromJSON populates collection's elements from the input JSON representation. FromJSON([]byte) error // UnmarshalJSON @implements json.Unmarshaler UnmarshalJSON([]byte) error }
JSONDeserializer provides JSON deserialization