utils

package
v0.0.0-...-4c3e4d9 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: MIT Imports: 1 Imported by: 25

Documentation

Overview

Package utils has various utils used by algo and dstruct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add[T Number](a, b T) T

Add is a wrapper around the plus operator.

func And

func And(a, b bool) bool

And is the logical or.

func Append

func Append[T any](acc []T, t T) []T

Append is a wrapper around the append built-in.

func Div

func Div[T Number](a, b T) T

Div is a wrapper around the division operator. Unsafe from division by zero.

func Eq

func Eq[T Number](a, b T) bool

Eq is wrapper around the == operator.

func Ge

func Ge[T Number](a, b T) bool

Ge is wrapper around the >= operator.

func Gt

func Gt[T Number](a, b T) bool

Gt is wrapper around the > operator.

func Identity

func Identity[T any](a T) T

Identity does not mutate the object.

func Le

func Le[T Number](a, b T) bool

Le is wrapper around the <= operator.

func Lt

func Lt[T Number](a, b T) bool

Lt is wrapper around the < operator.

func Max

func Max[T Number](a, b T) T

Max returns the maximum between two numbers.

func Min

func Min[T Number](a, b T) T

Min returns the minimum between two numbers.

func Mul

func Mul[T Number](a, b T) T

Mul is a wrapper around the product operator.

func Or

func Or(a, b bool) bool

Or is the logical or.

func Sub

func Sub[T Number](a, b T) T

Sub is a wrapper around the minus operator.

Types

type Comparator

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

Comparator is a function that returns a boolean based on two inputs. It should be stateless, and allow for a total ordering of elements in T such that a precedes b if, and only if, Comparator(a,b)==true. Functions that require a comparator input will assume as much.

func Equal

func Equal[T any](comp Comparator[T]) Comparator[T]

Equal takes returns an equality check. Two items are considered equal if their position is equivalent according to the ordering defined by the comparator.

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Number constrains numeric values.

type Predicate

type Predicate[T any] func(a T) bool

Predicate is a function that returns a boolean based on a single input. Furthermore, it should be stateless. Functions that require a predicate input will assume as much.

type Signed

type Signed interface {
	constraints.Signed | constraints.Float
}

Signed constrains to Numbers where negative values can be represented.

type SignedInt

type SignedInt interface {
	constraints.Signed
}

SignedInt to integers where negative values can be represented.

Jump to

Keyboard shortcuts

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