types

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToInt added in v0.3.4

func BoolToInt(b bool) int

func CastFloat

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

func CastInteger

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

func CastNumber

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

func CastSigned

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

func CastUnsigned

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

func Match

func Match[T any](yes bool, a, b T) T

func ResultVal

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

func Zero

func Zero[T any]() T

func Zero2

func Zero2[T any]() T

Types

type Basic

type Basic struct {
}

type BinaryFunction added in v0.3.1

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

BinaryFunction 将两个类型转为第三个类型

type BinaryKVFunction added in v0.3.1

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

type BinaryKVFunction2 added in v0.3.1

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

type BinaryKVOperator added in v0.3.1

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

type BinaryOperator added in v0.3.1

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

BinaryOperator 输入两个相同类型的参数,对其做二元运算,返回相同类型的结果

type Bool

type Bool int8

func (Bool) IsFalse

func (b Bool) IsFalse() bool

func (Bool) IsNone

func (b Bool) IsNone() bool

func (Bool) IsTrue

func (b Bool) IsTrue() bool

func (Bool) MarshalBinary

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

MarshalBinary

func (Bool) MarshalJSON

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

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 added in v0.3.1

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

Comparator 比较两个元素. 第一个元素大于第二个元素时,返回正数; 第一个元素小于第二个元素时,返回负数; 否则返回 0.

type ComparatorKV added in v0.3.1

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

Comparator 比较两个元素. 第一个元素大于第二个元素时,返回正数; 第一个元素小于第二个元素时,返回负数; 否则返回 0.

type Consumer added in v0.3.1

type Consumer[T any] func(T)

Consumer 消费一个元素

type ConsumerKV added in v0.3.1

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

ConsumerKV 消费一个KV

type Dict

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

type Enum

type Enum[T constraints.Unsigned | ~string] struct {
	Value T
}

type Func added in v0.3.1

type Func func()

type FuncRetry added in v0.3.1

type FuncRetry func(times uint) (retry bool)

func (FuncRetry) Do added in v0.3.1

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

type FuncReturnDataOrErr added in v0.3.1

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

type FuncReturnErr added in v0.3.1

type FuncReturnErr func() error

type GrpcServiceMethod added in v0.3.1

type GrpcServiceMethod[REQ, RES any] func(context.Context, REQ) (RES, error)

type ID

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

func (ID[KEY]) Key

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

type Int

type Int int

func (Int) Key

func (s Int) Key() int

type Less added in v0.3.1

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

type LessKV added in v0.3.1

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

type Option

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

返回option 返回时会有两次复制value,后续使用还有可能更多次,自行选择用不用

func MapOption

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

func Nil

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

func None

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

func Some

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

func (*Option[T]) Get

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

func (*Option[T]) IfNone

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

func (*Option[T]) IfSome

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

func (*Option[T]) IsNone

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

func (*Option[T]) IsSome

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

func (*Option[T]) MarshalJSON

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

func (*Option[T]) UnmarshalJSON

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

func (*Option[T]) Unwrap

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

func (*Option[T]) UnwrapOr

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

func (*Option[T]) UnwrapOrElse

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

func (*Option[T]) Val

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

type OptionPtr added in v0.1.0

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

func MapOptionPtr added in v0.1.0

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

func NilPtr added in v0.1.0

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

func NonePtr added in v0.1.0

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

func SomePtr added in v0.1.0

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

func (OptionPtr[T]) Get added in v0.1.0

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

func (OptionPtr[T]) IfNone added in v0.1.0

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

func (OptionPtr[T]) IfSome added in v0.1.0

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

func (OptionPtr[T]) IsNone added in v0.1.0

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

func (OptionPtr[T]) IsSome added in v0.1.0

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

func (OptionPtr[T]) MarshalJSON added in v0.1.0

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

func (*OptionPtr[T]) UnmarshalJSON added in v0.1.0

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

func (OptionPtr[T]) Unwrap added in v0.1.0

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

func (OptionPtr[T]) UnwrapOr added in v0.1.0

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

func (OptionPtr[T]) UnwrapOrElse added in v0.1.0

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

func (OptionPtr[T]) Val added in v0.1.0

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

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]

func PairPtrOf added in v0.1.0

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

func (*Pair[T1, T2]) Val

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

type Predicate added in v0.3.1

type Predicate[T any] func(T) bool

Predicate 断言是否满足指定条件

type PredicateKV added in v0.3.1

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

Predicate 断言是否满足指定条件

type Ref

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

func RefOf

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

func (Ref[T]) Get

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

func (Ref[T]) IsNil

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

func (Ref[T]) IsNotNil

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

func (Ref[T]) Set

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

func (Ref[T]) Val

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

type Result

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

func Err

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

func Ok

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

func (Result[T]) IfErr

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

func (Result[T]) IfOk

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

func (Result[T]) IsErr

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

func (Result[T]) IsErrAnd

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

func (Result[T]) IsOk

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

func (Result[T]) IsOkAnd

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

func (*Result[T]) MarshalJSON

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

func (Result[T]) Or

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

func (Result[T]) OrDefault

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

func (Result[T]) OrPanic

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

func (*Result[T]) UnmarshalJSON

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

func (Result[T]) Val

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

type String

type String string

func (String) Key

func (s String) Key() string

type Supplier added in v0.3.1

type Supplier[T any] func() T

Supplier 产生一个元素

type SupplierKV added in v0.3.1

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

SupplierKV 产生一个KV

type Task added in v0.3.1

type Task func(context.Context)

type TaskWithErr added in v0.3.1

type TaskWithErr 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]

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

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

type UnaryFunction added in v0.3.1

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

UnaryFunction 将一个类型转为另一个类型

type UnaryKVFunction added in v0.3.1

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

UnaryKVFunction 将一个类型转为另一个类型

type UnaryKVFunction2 added in v0.3.1

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

type UnaryKVOperator added in v0.3.1

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

type UnaryOperator added in v0.3.1

type UnaryOperator[T any] func(T) T

UnaryOperator 对输入进行一元运算返回相同类型的结果

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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