types

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT, Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyStruct = struct{}{}

Functions

func BoolToInt

func BoolToInt(b bool) int

BoolToInt returns the result.

func CastFloat

func CastFloat[T, V constraints.Float](v V) T

CastFloat converts the value.

func CastInteger

func CastInteger[T, V constraints.Integer](v V) T

CastInteger converts the value.

func CastNumber

func CastNumber[T, V constraintsi.Number](v V) T

CastNumber converts the value.

func CastSigned

func CastSigned[T, V constraints.Signed](v V) T

CastSigned converts the value.

func CastUnsigned

func CastUnsigned[T, V constraints.Unsigned](v V) T

CastUnsigned converts the value.

func ResultVal

func ResultVal[T any](v T, err error) T

ResultVal returns the result.

Types

type Basic

type Basic struct {
}

type BinaryFunction

type BinaryFunction[T, R, U any] func(T, R) U

BinaryFunction converts two inputs to a third type.

type BinaryKVFunction

type BinaryKVFunction[K, V, R, U any] func(K, V, R) U

type BinaryKVFunction2

type BinaryKVFunction2[K, V, RK, RV, UK, UV any] func(K, V, RK, RV) (UK, UV)

type BinaryKVOperator

type BinaryKVOperator[K, V any] func(K, V, K, V) (K, V)

type BinaryOperator

type BinaryOperator[T any] func(T, T) T

BinaryOperator applies a binary operation to two values of the same type and returns the same type.

type Bool

type Bool int8

func (Bool) IsFalse

func (b Bool) IsFalse() bool

IsFalse reports whether the condition holds.

func (Bool) IsNone

func (b Bool) IsNone() bool

IsNone reports whether the condition holds.

func (Bool) IsTrue

func (b Bool) IsTrue() bool

IsTrue reports whether the condition holds.

func (Bool) MarshalBinary

func (b Bool) MarshalBinary() ([]byte, error)

MarshalBinary

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value.

func (Bool) MarshalText

func (b Bool) MarshalText() ([]byte, error)

MarshalText

func (Bool) String

func (b Bool) String() string

String implements Stringer.

func (*Bool) UnmarshalBinary

func (b *Bool) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Bool) UnmarshalText

func (b *Bool) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Comparator

type Comparator[T any] func(T, T) int

Comparator compares two elements. If the first element is greater than the second, it returns a positive number; if the first element is less than the second, it returns a negative number; otherwise it returns 0.

type ComparatorKV

type ComparatorKV[K, V any] func(K, V, K, V) int

Comparator compares two elements. If the first element is greater than the second, it returns a positive number; if the first element is less than the second, it returns a negative number; otherwise it returns 0.

type Consumer

type Consumer[T any] func(T)

Consumer consumes an element.

type ConsumerKV

type ConsumerKV[K, V any] func(K, V)

ConsumerKV consumes a key/value pair.

type Dict

type Dict[K comparable, V any] struct {
	Key   K
	Value V
}

type Enum

type Enum[T constraintsi.Enum] int32

func (Enum[T]) MarshalJSON

func (t Enum[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value.

func (Enum[T]) MarshalText

func (t Enum[T]) MarshalText() ([]byte, error)

MarshalText encodes the value.

func (*Enum[T]) UnmarshalJSON

func (t *Enum[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes into the value.

func (*Enum[T]) UnmarshalText

func (t *Enum[T]) UnmarshalText(data []byte) error

UnmarshalText decodes into the value.

type Func

type Func func()

type FuncRetry

type FuncRetry func(times uint) (retry bool)

func (FuncRetry) Do

func (f FuncRetry) Do(times uint) (retry bool)

Do performs the retry logic.

type FuncReturnDataOrErr

type FuncReturnDataOrErr[T any] func() (T, error)

type FuncReturnErr

type FuncReturnErr func() error

type ID

type ID[T constraintsi.ID] struct {
	Id T `json:"id"`
}

func (ID[KEY]) Key

func (s ID[KEY]) Key() KEY

Key returns the wrapped ID value.

type Int

type Int int

func (Int) Key

func (s Int) Key() int

Key returns the underlying value.

type Less

type Less[T any] func(T, T) bool

type LessKV

type LessKV[K, V any] func(K, V, K, V) bool

type Option

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

Returning an Option can copy the value multiple times; decide whether you need it.

func MapOption

func MapOption[T any, R any](opt Option[T], fn func(T) R) Option[R]

MapOption maps the contained value to another type.

func Nil

func Nil[T any]() Option[T]

Nil creates an empty Option.

func None

func None[T any]() Option[T]

None creates an empty Option.

func Some

func Some[T any](v T) Option[T]

Some creates an Option containing v.

func (*Option[T]) Get

func (opt *Option[T]) Get() (T, bool)

Get returns the value and whether it is present.

func (*Option[T]) IfNone

func (opt *Option[T]) IfNone(action func())

IfNone runs action if the Option is empty.

func (*Option[T]) IfSome

func (opt *Option[T]) IfSome(action func(value T))

IfSome runs action if the Option contains a value.

func (*Option[T]) IsNone

func (opt *Option[T]) IsNone() bool

IsNone reports whether the condition holds.

func (*Option[T]) IsSome

func (opt *Option[T]) IsSome() bool

IsSome reports whether the condition holds.

func (*Option[T]) MarshalJSON

func (opt *Option[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value, or null if the Option is empty.

func (*Option[T]) UnmarshalJSON

func (opt *Option[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the value, or leaves the Option empty for null.

func (*Option[T]) Unwrap

func (opt *Option[T]) Unwrap() T

Unwrap returns the value or panics if the Option is empty.

func (*Option[T]) UnwrapOr

func (opt *Option[T]) UnwrapOr(def T) T

UnwrapOr returns the value or def if the Option is empty.

func (*Option[T]) UnwrapOrElse

func (opt *Option[T]) UnwrapOrElse(fn func() T) T

UnwrapOrElse returns the value or calls fn if the Option is empty.

func (*Option[T]) Val

func (opt *Option[T]) Val() (T, bool)

Val returns the value and whether it is present.

type OptionPtr

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

func MapOptionPtr

func MapOptionPtr[T any, R any](opt OptionPtr[T], fn func(*T) *R) OptionPtr[R]

MapOptionPtr maps the contained value to another pointer type.

func NilPtr

func NilPtr[T any]() OptionPtr[T]

NilPtr creates an empty OptionPtr.

func NonePtr

func NonePtr[T any]() OptionPtr[T]

NonePtr creates an empty OptionPtr.

func SomePtr

func SomePtr[T any](v *T) OptionPtr[T]

SomePtr creates an OptionPtr containing v.

func (OptionPtr[T]) Get

func (opt OptionPtr[T]) Get() (*T, bool)

Get returns the value and whether it is present.

func (OptionPtr[T]) IfNone

func (opt OptionPtr[T]) IfNone(action func())

IfNone runs action if the OptionPtr is empty.

func (OptionPtr[T]) IfSome

func (opt OptionPtr[T]) IfSome(action func(value *T))

IfSome runs action if the OptionPtr contains a value.

func (OptionPtr[T]) IsNone

func (opt OptionPtr[T]) IsNone() bool

IsNone reports whether the condition holds.

func (OptionPtr[T]) IsSome

func (opt OptionPtr[T]) IsSome() bool

IsSome reports whether the condition holds.

func (OptionPtr[T]) MarshalJSON

func (opt OptionPtr[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value, or null if the OptionPtr is empty.

func (*OptionPtr[T]) UnmarshalJSON

func (opt *OptionPtr[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the value, or leaves the OptionPtr empty for null.

func (OptionPtr[T]) Unwrap

func (opt OptionPtr[T]) Unwrap() *T

Unwrap returns the value or panics if the OptionPtr is empty.

func (OptionPtr[T]) UnwrapOr

func (opt OptionPtr[T]) UnwrapOr(def *T) *T

UnwrapOr returns the value or def if the OptionPtr is empty.

func (OptionPtr[T]) UnwrapOrElse

func (opt OptionPtr[T]) UnwrapOrElse(fn func() *T) *T

UnwrapOrElse returns the value or calls fn if the OptionPtr is empty.

func (OptionPtr[T]) Val

func (opt OptionPtr[T]) Val() (*T, bool)

Val returns the value and whether it is present.

type Pair

type Pair[T1 any, T2 any] struct {
	First  T1
	Second T2
}

func PairOf

func PairOf[T1 any, T2 any](f T1, s T2) Pair[T1, T2]

PairOf returns the result.

func PairPtrOf

func PairPtrOf[T1 any, T2 any](f T1, s T2) *Pair[T1, T2]

PairPtrOf returns the result.

func (*Pair[T1, T2]) Val

func (a *Pair[T1, T2]) Val() (T1, T2)

Val returns the value.

type Predicate

type Predicate[T any] func(T) bool

Predicate checks whether a value satisfies a condition.

type PredicateKV

type PredicateKV[K, V any] func(K, V) bool

Predicate checks whether a key/value pair satisfies a condition.

type Ref

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

func RefOf

func RefOf[T any](v *T) Ref[T]

RefOf returns the result.

func (Ref[T]) Get

func (a Ref[T]) Get() T

Get returns the value.

func (Ref[T]) IsNil

func (a Ref[T]) IsNil() bool

IsNil reports whether the condition holds.

func (Ref[T]) IsNotNil

func (a Ref[T]) IsNotNil() bool

IsNotNil reports whether the condition holds.

func (Ref[T]) Set

func (a Ref[T]) Set(v T) T

Set updates or inserts a value.

func (Ref[T]) Val

func (a Ref[T]) Val() (v T, ok bool)

Val returns the value.

type Result

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

func Err

func Err[T any](a error) Result[T]

Err returns the value.

func Ok

func Ok[T any](a T) Result[T]

Ok returns the value.

func (Result[T]) IfErr

func (a Result[T]) IfErr(action func(err error))

IfErr performs the operation.

func (Result[T]) IfOk

func (a Result[T]) IfOk(action func(value T))

IfOk performs the operation.

func (Result[T]) IsErr

func (a Result[T]) IsErr() bool

IsErr reports whether the condition holds.

func (Result[T]) IsErrAnd

func (a Result[T]) IsErrAnd(f func(error) bool) bool

IsErrAnd reports whether the condition holds.

func (Result[T]) IsOk

func (a Result[T]) IsOk() bool

IsOk reports whether the condition holds.

func (Result[T]) IsOkAnd

func (a Result[T]) IsOkAnd(f func(T) bool) bool

IsOkAnd reports whether the condition holds.

func (*Result[T]) MarshalJSON

func (a *Result[T]) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value.

func (Result[T]) Or

func (a Result[T]) Or(value T) T

Or returns the value.

func (Result[T]) OrDefault

func (a Result[T]) OrDefault() (v T)

OrDefault returns the value.

func (Result[T]) OrPanic

func (a Result[T]) OrPanic() T

OrPanic returns the value.

func (*Result[T]) UnmarshalJSON

func (a *Result[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes into the value.

func (Result[T]) Val

func (a Result[T]) Val() (value T, err error)

Val returns the value.

type Service added in v1.11.3

type Service[REQ, RESP any] func(context.Context, REQ) (RESP, error)

type String

type String string

func (String) Key

func (s String) Key() string

Key returns the underlying value.

type Supplier

type Supplier[T any] func() T

Supplier produces an element.

type SupplierKV

type SupplierKV[K, V any] func() (K, V)

SupplierKV produces a key/value pair.

type Task

type Task func(context.Context)

type TaskReturnErr added in v1.11.3

type TaskReturnErr func(context.Context) error

type Tuple

type Tuple[T1 any, T2 any, T3 any] struct {
	First  T1
	Second T2
	Third  T3
}

func TupleOf

func TupleOf[T1 any, T2 any, T3 any](f T1, s T2, t T3) *Tuple[T1, T2, T3]

TupleOf returns the result.

func (*Tuple[T1, T2, T3]) Val

func (a *Tuple[T1, T2, T3]) Val() (T1, T2, T3)

Val returns the value.

type UnaryFunction

type UnaryFunction[T, R any] func(T) R

UnaryFunction converts a value from one type to another.

type UnaryKVFunction

type UnaryKVFunction[K, V, R any] func(K, V) R

UnaryKVFunction converts a key/value pair to another value.

type UnaryKVFunction2

type UnaryKVFunction2[K, V, RK, RV any] func(K, V) (RK, RV)

type UnaryKVOperator

type UnaryKVOperator[K, V any] func(K, V) (K, V)

type UnaryOperator

type UnaryOperator[T any] func(T) T

UnaryOperator applies a unary operation and returns a value of the same type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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