generic

package
v0.0.0-...-24ca9bf Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Mapping2 = ExampleMap[any]{
	"any":  MyFuncAny,
	"a":    anything{"stuff"}.ExampleFunc,
	"fake": func(ex any) any { return "fake" },
}

Mapping2 maps string names to examples. The examples are stored as functions with the signature

func(ex T) T

which is instantiated to

func(ex any) any

in this example

Functions

func AddOne

func AddOne(ex int) int

func AssertFalse

func AssertFalse(t *testing.T, got bool)

func AssertTrue

func AssertTrue(t *testing.T, got bool)

func ListOrderedKinds

func ListOrderedKinds() []string

func Max

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

func Min

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

func MinMax

func MinMax[T Ordered](a, b T) (T, T)

func MyFuncAny

func MyFuncAny(ex any) any

func MyFuncInt

func MyFuncInt(ex int) int

func PrintExample

func PrintExample[T any](ex T)

func RandomNumber

func RandomNumber[T Number]() T

func RandomNumberList

func RandomNumberList[T IntType](n int) []T

func Scale

func Scale[E IntType](s []E, c E) []E

func SmallIntList

func SmallIntList(n int) []int

func TryMapping1

func TryMapping1()

Types

type AllOrdered

type AllOrdered interface {
	Number | ~string | uintptr
}

All Ordered types string int, int16, int32, int64, int8 uint, uint16, uint32, uint64, uint8 float32, float64 uintptr

type Comparable

type Comparable interface {
	comparable
}

type Example

type Example[T any] func(ex T) T

type ExampleMap

type ExampleMap[T any] map[string]func(ex T) T

type FloatLister

type FloatLister interface {
	sort.Interface
	String() string
}

type FloatStringer

type FloatStringer interface {
	~float32 | ~float64 // union of types
	String() string
}

Reference: https://codilime.com/blog/generics-in-go-definition-history-and-examples-of-use/

type FloatType

type FloatType interface {
	float32 | float64
}

type IExample

type IExample[T any] interface {
	ExampleFunc(ex T) T
}

type IExampleMap

type IExampleMap[T any] map[string]interface{ ExampleFunc(ex T) T }

type IntType

type IntType interface {
	int | int8 | int16 | int32 | int64
}

type KindInfo

type KindInfo struct {
	Comparable       bool // if it is useful ...
	Ordered          bool // some alternatives provided here
	DeeplyComparable bool // if it is useful ...
	Alternate        bool // some alternatives provided here
	Iterable         bool // some alternatives provided here
}

type Number

type Number interface {
	IntType | UintType | FloatType
}

type Ordered

type Ordered interface {
	Number | ~string
}

type Sort

type Sort interface {
	// Len is the number of elements in the collection.
	Len() int

	// Less reports whether the element with index i
	// must sort before the element with index j.
	//
	// If both Less(i, j) and Less(j, i) are false,
	// then the elements at index i and j are considered equal.
	// Sort may place equal elements in any order in the final result,
	// while Stable preserves the original input order of equal elements.
	//
	// Less must describe a transitive ordering:
	//  - if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
	//  - if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
	//
	// Note that floating-point comparison (the < operator on float32 or float64 values)
	// is not a transitive ordering when not-a-number (NaN) values are involved.
	// See Float64Slice.Less for a correct implementation for floating-point values.
	Less(i, j int) bool

	// Swap swaps the elements with indexes i and j.
	Swap(i, j int)
}

An implementation of Interface can be sorted by the routines in this package. The methods refer to elements of the underlying collection by integer index.

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (T, bool)

func (*Stack[T]) Push

func (s *Stack[T]) Push(value T)

type Stringable

type Stringable interface {
	IntType | UintType
}

type UintType

type UintType interface {
	uint | uint8 | uint16 | uint32 | uint64
}

Directories

Path Synopsis
example command
examples/addone command
examples/gitit command
gnuflags
standard command line flags based on GNU standards.
standard command line flags based on GNU standards.
package main contains a Response to Stack Overflow question 71677581
package main contains a Response to Stack Overflow question 71677581
71677581
package main contains a Response to Stack Overflow question 71677581
package main contains a Response to Stack Overflow question 71677581
Package sort provides a generic implementation of the standard library sort package primitives for sorting slices and user-defined collections.
Package sort provides a generic implementation of the standard library sort package primitives for sorting slices and user-defined collections.

Jump to

Keyboard shortcuts

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