cmp

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package cmp provides comparators for sorting linked lists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LessThanCustom

func LessThanCustom[T Orderable[T]](a, b T) bool

LessThanCustom converts types that implement OrderableUser interface.

func LessThanNative

func LessThanNative[T OrderableNative](a, b T) bool

LessThanNative provides a wrapper around the < operator for types that support it, and can be used for sorting lists of compatible types.

func LessThanTime

func LessThanTime(a, b time.Time) bool

LessThanTime compares time using the time.Time.Before() method.

Types

type LessThan

type LessThan[T any] func(a, b T) bool

LessThan describes a less than operation, typically provided by one of the following operations.

func LessThanConverter

func LessThanConverter[T any, S OrderableNative](converter func(T) S) LessThan[T]

LessThanConverter provides a function to convert a non-orderable type to an orderable type. Use this for

func Reverse

func Reverse[T any](fn LessThan[T]) LessThan[T]

Reverse wraps an existing LessThan operator and reverses it's direction.

type Orderable

type Orderable[T any] interface{ LessThan(T) bool }

OrderableUser allows users to define a method on their types which implement a method to provide a LessThan operation.

type OrderableNative

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

OrderableNative describes all native types which (currently) support the < operator. To order custom types, use the OrderableUser interface.

In the future an equivalent oderable type specification is likely to enter the standard library, which will supercede this type.

Jump to

Keyboard shortcuts

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