ord

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Conform

func Conform[A any, CA Class[A]](c CA) func(t *testing.T, x, y, z A)

Conform returns a function testing if the implementation abides by its laws.

Types

type Class

type Class[A any] interface {
	eq.Class[A]

	Compare(A, A) Ordering

	LT(A, A) bool
	LTE(A, A) bool
	GT(A, A) bool
	GTE(A, A) bool

	Max(A, A) A
	Min(A, A) A
}

type CompareFn

type CompareFn[A any] func(A, A) Ordering

func FromLTE

func FromLTE[A any](lteFn LTEFn[A]) CompareFn[A]

FromLTE derives a CompareFn using the provide LTEFn.

type EQ

type EQ struct{}

type GT

type GT struct{}

type LT

type LT struct{}

type LTEFn

type LTEFn[A any] func(A, A) bool

type Ordering

type Ordering interface {
	// contains filtered or unexported methods
}

func Ordered

func Ordered[A constraints.Ordered](x, y A) Ordering

Ordered implements CompareFn for natively ordered types.

type Type

type Type[A any] struct {
	eq.Type[A]
	// contains filtered or unexported fields
}

func NewType

func NewType[A any](compareFn CompareFn[A]) Type[A]

NewType derives a type implementing Class.

Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/ord"
)

func main() {
	t := ord.NewType(ord.Ordered[int])

	fmt.Println(t.LT(5, 6))

}
Output:

true

func (Type[A]) Compare

func (t Type[A]) Compare(x, y A) Ordering

func (Type[A]) GT

func (t Type[A]) GT(x, y A) bool

func (Type[A]) GTE

func (t Type[A]) GTE(x, y A) bool

func (Type[A]) LT

func (t Type[A]) LT(x, y A) bool

func (Type[A]) LTE

func (t Type[A]) LTE(x, y A) bool

func (Type[A]) Max

func (t Type[A]) Max(x, y A) A

func (Type[A]) Min

func (t Type[A]) Min(x, y A) A

Jump to

Keyboard shortcuts

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