types

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: MIT Imports: 0 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BiFunction

type BiFunction func(t T, u U) R

BiFunction like Function, but is accepts two arguments and produces a result

type BinaryOperator

type BinaryOperator func(e1 T, e2 T) T

BinaryOperator is a BiFunction which input and result are the same type

type Comparator

type Comparator func(left T, right T) int

Comparator is a BiFunction, which two input arguments are the type, and returns a int. if left is greater then right, it returns a positive number; if left is less then right, it returns a negative number; if the two input are equal, it returns 0

var (
	// IntComparator is a Comparator for int
	IntComparator Comparator = func(left, right T) int {
		if left.(int) < right.(int) {
			return -1
		}
		if left.(int) > right.(int) {
			return 1
		}
		return 0
	}
	// Int64Comparator is a Comparator for int64
	Int64Comparator Comparator = func(left, right T) int {
		if left.(int64) > right.(int64) {
			return 1
		}
		if left.(int64) < right.(int64) {
			return -1
		}
		return 0
	}
)

func ReverseOrder

func ReverseOrder(cmp Comparator) Comparator

ReverseOrder returns the reverse order of the input Comparator

type Consumer

type Consumer func(e T)

Consumer accepts one argument and not produces any result

type Function

type Function func(e T) R

Function represents a conversion ability, which accepts one argument and produces a result

type IntFunction

type IntFunction func(e T) int

IntFunction is a Function, which result type is int

type Pair added in v0.0.2

type Pair struct {
	First  T
	Second R
}

type Predicate

type Predicate func(e T) bool

Predicate is a Function, which produces a bool value. usually used to test a value whether satisfied condition

type R

type R interface{}

R is another `any` type used to distinguish T

type Supplier

type Supplier func() T

Supplier returns a result. each time invoked it can returns a new or distinct result

type T

type T interface{}

T is a empty interface, that is `any` type. since Go is not support generics now(but will coming soon), so we use T to represent any type

type U

type U interface{}

U is another `any` type used to distinguish T and R

type UnaryOperator

type UnaryOperator func(e T) T

UnaryOperator is a Function, which argument and result are the same type

Jump to

Keyboard shortcuts

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