basic

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

This package holds the concrete implementation of several simple data structures that can be used from any package. This package imports no other packages, meaning this package can be imported everywhere.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pair

type Pair[T any, U any] struct {
	A T
	B U
}

func NewPair

func NewPair[T any, U any]() Pair[T, U]

This is occasionally useful for passing a factory to something.

type Triple

type Triple[T any, U any, V any] struct {
	A T
	B U
	C V
}

func NewTriple

func NewTriple[T any, U any, V any]() Triple[T, U, V]

This is occasionally useful for passing a factory to something.

type Variant

type Variant[A any, B any] struct {
	// contains filtered or unexported fields
}

A variant type that can hold one of two types at a single time. The underlying value can be accessed through methods of the variant. Trying to access the wrong value will result in a panic unless a default value is supplied. The size of the struct will be equal to the largest type plus one byte which is used to specify which value is in the variant.

func NewVariant

func NewVariant[A any, B any]() Variant[A, B]

func (Variant[A, B]) HasA

func (v Variant[A, B]) HasA() bool

Returns true if the variant holds value A.

func (Variant[A, B]) HasB

func (v Variant[A, B]) HasB() bool

Returns true if the variant holds value B.

func (Variant[A, B]) SetValA

func (v Variant[A, B]) SetValA(newVal A) Variant[A, B]

Sets the variant to hold value type A, initilized with the value passed to the function. After calling this method the variant will panic if value type B is attempted to be accessed.

func (Variant[A, B]) SetValB

func (v Variant[A, B]) SetValB(newVal B) Variant[A, B]

Sets the variant to hold value type B, initilized with the value passed to the function. After calling this method the variant will panic if value type A is attempted to be accessed.

func (Variant[A, B]) ValA

func (v Variant[A, B]) ValA() A

Attempts to return value A from the variant. Panics if the variant does not hold type A.

func (Variant[A, B]) ValAOr

func (v Variant[A, B]) ValAOr(_default A) A

Attempts to return value A from the variant. If the variant does not hold type A then it will return the default value.

func (Variant[A, B]) ValB

func (v Variant[A, B]) ValB() B

Attempts to return value B from the variant. Panics if the variant does not hold type B.

func (Variant[A, B]) ValBOr

func (v Variant[A, B]) ValBOr(_default B) B

Attempts to return value B from the variant. If the variant does not hold type B then it will return the default value.

type WidgetPair

type WidgetPair[
	T any,
	U any,
	TI widgets.BaseInterface[T],
	UI widgets.BaseInterface[U],
] Pair[T, U]

func (*WidgetPair[T, U, TI, UI]) Eq

func (_ *WidgetPair[T, U, TI, UI]) Eq(
	l *WidgetPair[T, U, TI, UI],
	r *WidgetPair[T, U, TI, UI],
) bool

func (*WidgetPair[T, U, TI, UI]) Hash

func (_ *WidgetPair[T, U, TI, UI]) Hash(
	other *WidgetPair[T, U, TI, UI],
) hash.Hash

func (*WidgetPair[T, U, TI, UI]) Zero

func (_ *WidgetPair[T, U, TI, UI]) Zero(other *WidgetPair[T, U, TI, UI])

type WidgetTriple

type WidgetTriple[
	T any,
	U any,
	V any,
	TI widgets.BaseInterface[T],
	UI widgets.BaseInterface[U],
	VI widgets.BaseInterface[V],
] Triple[T, U, V]

func (*WidgetTriple[T, U, V, TI, UI, VI]) Eq

func (_ *WidgetTriple[T, U, V, TI, UI, VI]) Eq(
	l *WidgetTriple[T, U, V, TI, UI, VI],
	r *WidgetTriple[T, U, V, TI, UI, VI],
) bool

func (*WidgetTriple[T, U, V, TI, UI, VI]) Hash

func (_ *WidgetTriple[T, U, V, TI, UI, VI]) Hash(
	other *WidgetTriple[T, U, V, TI, UI, VI],
) hash.Hash

func (*WidgetTriple[T, U, V, TI, UI, VI]) Zero

func (_ *WidgetTriple[T, U, V, TI, UI, VI]) Zero(
	other *WidgetTriple[T, U, V, TI, UI, VI],
)

Jump to

Keyboard shortcuts

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